Created
June 6, 2011 07:05
Random number on iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Return a random integer number between low and high inclusive */ | |
int randomInt(int low, int high) | |
{ | |
return (arc4random() % (high-low+1)) + low; | |
} | |
/* Return a random BOOL value */ | |
BOOL randomBool() | |
{ | |
return (BOOL)randomInt(0, 1); | |
} | |
/* Return a random float between 0.0 and 1.0 */ | |
float randomClamp() | |
{ | |
return (float)(arc4random() % ((unsigned)RAND_MAX + 1)) / (float)((unsigned)RAND_MAX + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment