Slench255

Easy Randomizer

Aug 11th, 2012
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // a random class made to make arc4random() easier to work with
  2. // Random.h
  3. @interface Random : NSObject //class "Random" inherits from NSObject (good practice)
  4.  
  5. +(NSInteger) getValueBetween: (NSInteger)valA and: (NSInteger)valB; // + means static method
  6.  
  7. @end
  8.  
  9. // Random.m
  10. @implementation Random
  11.  
  12. +(NSInteger) getValueBetween: (NSInteger)valA and: (NSInteger)valB {
  13.     if(valA < valB) // if valA is smaller do the following, else swap the values
  14.         return valA + arc4random() % (valA - valB +1);
  15.     else
  16.         return valB + arc4random() % (valB - valA +1);
  17. }
  18.  
  19. @end
Advertisement
Add Comment
Please, Sign In to add comment