On Dec 4, 2005, at 7:59 AM, Brian Buckley wrote:

> How frequently would rand return a same value?  (In theory it would be
> never but does anyone know the reality?)

According to the Pickaxe, Kernel.rand is an implementation of the  
[Mersenne Twister][1] algorithm.  If that is still the case, then in  
reality it will begin repeating exactly the same numbers after  
2^19937-1 (approx. 4e6001) pseudo-random numbers, as that's the  
period of the MT.  The period is the point at which the exact same  
series of PRNs will begin again.  For example, if it started out as  
1, 2, 3, ..., then after 2^19937-1, it'd start again at 1, 2, 3.

But, that's not what you really care about.

Numbers will certainly repeat within the period, since the period is  
so much larger than our integer representation.  For example, a 32  
bit integer can only represent about 4e9.  So, the likelihood of  
getting any specific integer, in the 32 bit case, is 1/(2^32).  This  
is an extreme example:

5.times { p rand(2) }
5.times { p rand(1000) }

The bottom line is that the PRNs should be approximately uniformly  
distributed.  Apply that to your specific range, and you have your  
answer.

--Steve

[1]: http://en.wikipedia.org/wiki/Mersenne_twister