I was playing around with perl's rand() and noticed that when supplying an argument larger than 2^32, the last bits of the output becomes predictable.
The most clear way I found of illustrating it is with the following script:
srand(); for $i (1..10) { printf "%4x\n",rand(2**48)%2**16 }
Whenever I execute that the output is
5101
6378
2a23
62f2
8d15
effc
9657
2d16
f669
40c0
(It's not just the first 10 values, but I didn't see a point copying a long list of "random" numbers)
The call to srand() is superfluous, but it's there to make it easy to supply an argument, and see that it doesn't change anything.
I've tried this on:
- Debian squeeze having perl 5.10 (randbits=48)
- Debian wheezy having perl 5.14 (randbits=48)
- Debian jessie having perl 5.20 (randbits=48)
I know rand() is not supposed to be cryptographically secure, but the last 16 bits being predictable is worse than what I had understood. Am I using any of the function(s) wrong?