Bug #3128
closedRandomness specs
Description
=begin
What should be the Ruby specs for the new Random class (and existing Kernel.{s}rand)?
More precisely: what should one expect of any Ruby implementation?
Several degrees of similarity with MRI are possible:
Say r = Random.new(42) and N is an Integer
- r.rand(N) is included in 0...N
- r.rand(N) will eventually return all values in 0...N
- r.rand(N) will return any particular value in 0...N with a probability of around 1/N
<insert any any of the known random tests and/or a minimal period> - r is a Mersenne Twister
- r is MT19937
- r.rand(N) generates the same particular string on all platforms
Implementers are ultimately free to choose whichever implementation they prefer, of course.
Still, it would be preferable to state what is the expect behavior for the Ruby language, not just for MRI. If MRI's guarantees are stronger, these should be stated as such.
Current state of affairs:
The documentation for Random class states that it is a Mersenne Twister pseudo number generator (but doesn't state which), so this corresponds to level (3) above.
Kernel.rand states that currently, r is a modified MT19937.
The Ruby Standardization WG Draft doesn't document Kernel.rand yet (nor Random, of course).
Rubinius' implementation currently guarantees level 0 (and also level 1 if N is not too big)
JRuby's implementation guarantees level 1 (and also level 2 if N is not too big)
Python and Java both guarantee the same particular sequence; other algorithms might be available as subclasses of their Random class.
My personal choice would be in line with Java and Python: insure the exact same sequence for the Random class. Implementations are free to provide subclasses of Random for different/better/faster algorithms.
If deemed preferable, Kernel.rand could have much lower required standards to allow for better speed, in which case level (2) above seems like the strict minimum.
=end