Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

arc4random and % operator

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?

like image 583
Tony Avatar asked Sep 16 '26 04:09

Tony


1 Answers

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.

like image 82
ksol Avatar answered Sep 17 '26 22:09

ksol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!