arc4random and % operator

余生颓废 提交于 2019-12-10 10:13:37

问题


I have a question about the arc4random() function in Objective-C.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/8962848/arc4random-and-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!