1
나는이 방법이 있습니다무작위 부동을위한 수학 방정식?
- (float)randomFloatBetween:(float)num1 andLargerFloat:(float)num2 {
return ((float)arc4random()/ARC4RANDOM_MAX) * num2-num1 + num1;
}
을 내가 대신 다음에 대한 조건문을 사용하여 가능하면 것을 궁금 :
When the score is:
Score 0-20: I want a float between 4.0-4.5 using the above method
Score 21-40: I want a float between 3.0-3.5 using the above method
Score 41-60: I want a float between 2.5-3.0 using the above method
Score 61+: I want a float between 2.0-2.5 using the above method
: 나는이 같은 내 게임에 대한 임의의 부동 소수점을 만들고 싶어
이제 조건부를 사용할 수는 있지만이를 수행하는 것보다 쉬운 수학 공식이 있습니까?
감사합니다.
EDIT1 :
- (float)determineFloat {
if (score <= 60)
{
//Gets the tens place digit, asserting >= 0.
int f = fmax(floor((score - 1)/10), 0);
switch (f)
{
case 0:
case 1:
{
// return float between 4.0 and 4.5
[self randomFloatBetween:4.0 andLargerFloat:4.5];
}
case 2:
case 3:
{
// return float between 3.0 and 3.5
[self randomFloatBetween:3 andLargerFloat:3.5];
}
case 4:
case 5:
{
// return float between 2.5 and 3.0
[self randomFloatBetween:2.5 andLargerFloat:3];
}
default:
{
return 0;
}
}
}
else
{
// return float between 2.0 and 2.5
[self randomFloatBetween:2.0 andLargerFloat:2.5];
}
return;
}
괜찮나이? 또한 이것이 가장 효율적인 방법이라고 확신합니까?
조건부를 사용할 때 가장 효율적인 방법은 무엇입니까? if-> else if-> else if, 등 ...? –
최대 점수가 있습니까? –
아니요 최대 점수가 없습니다 –