Issue #3128 has been updated by marcandre (Marc-Andre Lafortune).

Assignee changed from marcandre (Marc-Andre Lafortune) to matz (Yukihiro Matsumoto)
Priority changed from Normal to Low

Hi,

mame (Yusuke Endoh) wrote:
> Marc-Andre, do you need discussion about this?

After your remarks and those of Nobu, the question becomes:

Should `Randomg.new(42); rand` return the same value in all Ruby implementations, or is the result implementation defined?

I'm assigning this to Matz.

----------------------------------------
RubySpec #3128: Randomness specs
https://bugs.ruby-lang.org/issues/3128#change-26325

Author: marcandre (Marc-Andre Lafortune)
Status: Assigned
Priority: Low
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 


=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://bugs.ruby-lang.org/