Xcode 关于swift3 ARC4随机_制服的混淆

Xcode 关于swift3 ARC4随机_制服的混淆,xcode,swift3,Xcode,Swift3,我对在Swift3中使用arc4random_uniform感到困惑。我的理解是,我可以设置使用Int(arc4random\u uniform(max value)+min start value)生成的最大值和最小值,以便Int(arc4random\u uniform(5)+1)应该给出一个介于1和5之间的值 然而,我下面的代码有时给出的值大于我的最大值,小于我的最小值 var whateverNumber = Int(arc4random_uniform(100) + 50); 如果您

我对在Swift3中使用
arc4random_uniform
感到困惑。我的理解是,我可以设置使用
Int(arc4random\u uniform(max value)+min start value)
生成的最大值和最小值,以便
Int(arc4random\u uniform(5)+1)
应该给出一个介于1和5之间的值

然而,我下面的代码有时给出的值大于我的最大值,小于我的最小值

var whateverNumber = Int(arc4random_uniform(100) + 50);

如果您想要50到100之间的随机数,那么您的代码应该是

var whateverNumber = Int(arc4random_uniform(50) + 50)

尝试此操作以获得介于50和100之间的随机数:

int minimumValue = 50;
int maximumValue = 100;
int randomNumber = minimumValue + arc4random() % (maximumValue - minimumValue);

我现在没有带mac电脑,但我会稍后再试。谢谢。我今天才试过,但上面的代码还是给了我3分。所以我不确定Swift 3或xcode是否有任何问题。不管怎样,我会尝试更多的东西,如果可以的话,也许会结束这个问题。我是论坛的新手。