Created
January 7, 2012 21:59
-
-
Save codeswimmer/1576189 to your computer and use it in GitHub Desktop.
iOS: Using arc4random() to get a floating point value between 0 and a given maximum value
This file contains hidden or 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
| /* | |
| Using arc4random() to get a floating point value between 0 and a given maximum value. Note that this produces a value that is double the precision of using rand(). | |
| */ | |
| -(double)randomValueFromZero:(double)toValue | |
| { | |
| return double val = floorf(((double)arc4random() / toValue) * 100.0f); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment