我想生成一个介于31到60之间的随机数。
所以我使用了rand(),但我认为它会给我一些时间,我需要同样的value.But,每一次它都应该给我新的值。
我该怎么做呢?
发布于 2013-06-19 22:10:40
我想我可以添加一个我在许多项目中使用的方法。
- (NSInteger)randomValueBetween:(NSInteger)min and:(NSInteger)max {
return (NSInteger)(min + arc4random_uniform(max + 1);
}如果我最终在许多文件中使用它,我通常会将宏声明为
#define RAND_FROM_TO(min,max) (min + arc4random_uniform(max + 1))例如。
NSInteger myInteger = RAND_FROM_TO(31,60) // 31, 32,..., 59, 60https://stackoverflow.com/questions/8050681
复制相似问题