arc4random and % operator

6.4k Views Asked by At

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

There are 1 best solutions below

7
On BEST ANSWER

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.