Here is the code to generate the random number between some 2 values.

http://www.cocos2d-iphone.org/forum/topic/28378

- (int) randomNumberFrom: (int) minValue to: (int) maxValue

{

double probability = rand() / 2147483648.0;

double range = maxValue - minValue + 1;

return (int)(range * probability + minValue);

}

- (int) randomNumberFrom: (int) minValue to: (int) maxValue except:(int) exceptValue

{

if(minValue == maxValue)

{

return minValue;

}

int result;

while(exceptValue == (result = [self randomNumberFrom:minValue to:maxValue]))

{

}

return result;

}

Reference taken from:

http://www.cocos2d-iphone.org/forum/topic/28378

## No comments:

## Post a Comment