Search code examples
iosobjective-cperformancecocoaarc4random

arc4random() efficiency breaks?


Kind of an oddball question here but should be pretty basic for someone familiar with the implementation of arc4random.

Does it use an appropriate integer based on the number you use after the modulo? Example it would use int for a number |255| or a long int for a number |2147483647| or does it just use something completely different implementation?

I don't really need a huge number but I wouldn't mind using as large of pool as I can without a hit to performance. So that's my reason for asking about this.


Solution

  • arc4random() and arc4random_uniform(UInt32) both return UInt32, so the size of the number you'll get is limited by that. I think that's actually something over 2 billion.