我不确定如何设置 arc4Random()
的格式以生成 200 到 300 之间的随机数。我想要 200、210、220 等数字..(不是 200、201 , 202, ...)
(Xcode 5.1.1, iOS)
有什么想法吗?
我的一段代码:
self.currentObstacX += arc4random()%(200+10) + 300;
...但它似乎无法满足我的需要。
提前谢谢你。
最佳答案
@PaulR 的答案会奏效,但最好像这样使用 arc4random_uniform
...
NSInteger number = 10 * arc4random_uniform(11) + 200;
来自文档...
arc4random_uniform() is recommended over constructions like ``arc4random() % upper_bound'' as it avoids "modulo bias" when the upper bound is not a power of two.
关于ios - arc4Random() - 生成数字 "jumping after 10",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25849758/