Last active
March 1, 2016 16:39
-
-
Save jaderfeijo/ec360b18401cad2c3564 to your computer and use it in GitHub Desktop.
NSNumber+Random
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
| // | |
| // Created by Jader Feijo on 06/02/2014. | |
| // Copyright (c) 2014 Jader Feijo. All rights reserved. | |
| // | |
| // @license MIT | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface NSNumber (Random) | |
| + (float)randomFloat; | |
| + (float)randomFloatBetween:(float)min and:(float)max; | |
| + (NSInteger)randomInteger; | |
| + (NSInteger)randomIntegerBetween:(NSInteger)min and:(NSInteger)max; | |
| @end |
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
| // | |
| // Created by Jader Feijo on 06/02/2014. | |
| // Copyright (c) 2014 Jader Feijo. All rights reserved. | |
| // | |
| // @license MIT | |
| // | |
| #import "NSNumber+Random.h" | |
| @implementation NSNumber (Random) | |
| + (float)randomFloat { | |
| return (float)arc4random() / UINT_MAX; | |
| } | |
| + (float)randomFloatBetween:(float)min and:(float)max { | |
| return min + (max - min) * [NSNumber randomFloat]; | |
| } | |
| + (NSInteger)randomInteger { | |
| return (NSInteger)arc4random(); | |
| } | |
| + (NSInteger)randomIntegerBetween:(NSInteger)min and:(NSInteger)max { | |
| return min + arc4random() % (max - min); | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment