Created
October 25, 2013 23:41
-
-
Save priore/7163498 to your computer and use it in GitHub Desktop.
Random numbers and random boolean values
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
| @implementation NSNumber (Randomizer) | |
| + (NSNumber*)randomNumberWithMin:(NSInteger)min max:(NSInteger)max | |
| { | |
| if (min>max) { | |
| int tempMax=max; | |
| max=min; | |
| min=tempMax; | |
| } | |
| int randomy=arc4random() % (max-min+1); | |
| randomy=randomy+min; | |
| return @(randomy); | |
| } | |
| + (NSInteger)randomIntegerWithMin:(NSInteger*)min max:(NSInteger*)max | |
| { | |
| return [[NSNumber randomNumberWithMin:min max:max] integerValue]; | |
| } | |
| + (BOOL)randomBoolean | |
| { | |
| return [NSNumber randomIntegerWithMin:0 max:1] == 0; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment