arc4random
uses Rivest Cipher 4. It a Substitution Cipher like the crudest Caesear Cipher. And for substitution it uses S-boxes which obviously expands as substitution boxes. In simple terms S-Boxes can be termed as lookup tables where you look for replacement of bytes. Read more on S-boxes.
And here the S-Boxes can be in 2^1700 different states (in simple words it can give that much variant substitution look-up tables, which generally can be a measure of cipher strength.). The whole process results in pseudo-random number, which means the numbers won't be truly random(I am not sure if true-random number generation is achieved yet.), i.e. the number will be dependent on something that was deterministic. And the function can give you any number in range 0-4294967296.
So what advantage it have over normal rand()
and random()
? it has a higher range (hopefully, more randomness than these two). But if you are using to get a small random number, the advantage diminishes, and I see you are doing it.
[derivationArray objectAtIndex:(arc4random() %derivationCount)]
So by modulo dividing the arc4random() output, you are restricting the final outcome to the range of 0 - derivationCount.
And that a lot of explanation!, but if you just want function definition, Read the manual!.
Edit from comments:
Instead of a modulo bias, use arc4random_uniform()
. Still there is no guarantee, that the numbers won't be repeated.