From: Caleb Clausen Date: 2010-04-12T02:30:18+09:00 Subject: [ruby-core:29452] Re: [RubySpec #3128] Randomness specs On 4/10/10, Marc-Andre Lafortune wrote: > RubySpec #3128: Randomness specs > http://redmine.ruby-lang.org/issues/show/3128 > > Author: Marc-Andre Lafortune > Status: Open, Priority: Normal > Category: core, Target version: 1.9.2 > > 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 Yes... and r.rand(N) should be an Integer. > 1) r.rand(N) will eventually return all values in 0...N I find this troubling, since it could imply that the random number generator obeys the mythical law of averages. You know better, I'm sure, but others may not. A written standard needs to be very clear about this, and use the appropriate statistical language. > 2) r.rand(N) will return any particular value in 0...N with a probability of > around 1/N > > 3) r is a Mersenne Twister > 4) r is MT19937 > 5) r.rand(N) generates the same particular string on all platforms 5) could be interpreted 2 ways, depending on the meaning of the ambiguous term 'platform'. 5a) All ruby implementations must generate the same sequence of random numbers as MRI from r.rand(N). 5b) A particular implementation must generate the same sequence of random numbers from r.rand(N), no matter what operating system it is used on. Of course, 5) only applies to pseudo-random number generators. One can easily imagine a subclass of Random which uses a truly random number generator. Testing (pseudo)random number generators is difficult, due to their (pseudo)nondeterministic nature.