问题描述
我对Objective-C中的arc4random()函数有疑问。
I have a question about the arc4random() function in Objective-C.
在网上看到的示例中,有一个在函数调用之后的%
符号。我认为%
是模运算符,因此在 arc4random()
之后使用时,此符号是否还有其他含义?
In the examples I have seen online, there is a %
symbol right after the function call. I think of %
as the modulus operator, so does this symbol have another meaning when used after arc4random()
? How does it work?
推荐答案
没有特殊含义。在 arc4random()
(或任何其他随机函数)之后应用模数是限制随机数的最小值/最大值的常见模式。例如, arc4random()%78
会为您返回0到77之间的数字。
No special meaning. Applying a modulus after arc4random()
(or any other random function) is a common pattern to restrict the min/max of the random. arc4random() % 78
will return you a number between 0 and 77, for example.
这篇关于arc4random和%运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!