priore

Random numbers and random boolean values

Jun 14th, 2013
981
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @implementation NSNumber (Randomizer)
  2.  
  3. + (NSNumber*)randomNumberWithMin:(NSInteger)min max:(NSInteger)max
  4. {
  5.     if (min>max) {
  6.         NSInteger tempMax=max;
  7.         max=min;
  8.         min=tempMax;
  9.     }
  10.     NSInteger randomy=arc4random() % (max-min+1);
  11.     randomy=randomy+min;
  12.     return @(randomy);
  13. }
  14.  
  15. + (NSInteger)randomIntegerWithMin:(NSInteger)min max:(NSInteger)max
  16. {
  17.     return [[NSNumber randomNumberWithMin:min max:max] integerValue];
  18. }
  19.  
  20. + (BOOL)randomBoolean
  21. {
  22.     return [NSNumber randomIntegerWithMin:0 max:1] == 0;
  23. }
  24.  
  25. @end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×