Issue #3128 has been updated by Hiroshi NAKAMURA.

Status changed from Open to Assigned
Assignee set to Hiroshi NAKAMURA
Target version changed from 1.9.2 to 1.9.3


----------------------------------------
RubySpec #3128: Randomness specs
http://redmine.ruby-lang.org/issues/3128

Author: Marc-Andre Lafortune
Status: Assigned
Priority: Normal
Assignee: Hiroshi NAKAMURA
Category: core
Target version: 1.9.3


=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
 
 0) r.rand(N) is included in 0...N
 1) r.rand(N) will eventually return all values in 0...N
 2) 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>
 3) r is a Mersenne Twister 
 4) r is MT19937
 5) 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



-- 
http://redmine.ruby-lang.org