From: Matthew Moss Date: 2009-01-24T03:58:28+09:00 Subject: Re: Separate random number generators? On Jan 23, 2009, at 9:53 AM, Bart Braem wrote: > On Jan 23, 4:33 pm, "F. Senault" wrote: >> Le 23 janvier 2009 à 15:59, Bart Braem a écrit : >> >>> On Jan 23, 3:34 pm, Lars Christensen wrote: >>>> I do think that my own solution (last on the page) is efficient, >>>> but i >>>> can't vouch for the statistical properties (it reseeds the Mersenne >>>> Twister in Ruby every time a number is drawn, although randomly). >> >>> I've tested this setup, with just one RNG. Running my unit tests is >>> about 5 times slower, unfortunately. I am calling the random number >>> very often, more than 10.000 times in 10 seconds in a simulation >>> that >>> uses the standard kernel rand. >>> I can't afford this slowdown, but it seems as though there are no >>> other solutions that do not use a pure-ruby library? >> >> Can you estimate the number of random numbers you'll need ? Maybe >> you >> could pre-generate sequences of numbers in a few arrays, then patch >> the >> rand method to actually read the array instead of generating the >> number ? >> >> The start time and memory consumption will be a lot higher, but >> maybe it >> makes a good compromise ? >> > > That is an idea, but quick calculations show the need of up to 100.000 > random numbers. Which is quite a lot to calculate and most importantly > store and retrieve again. How random do the numbers have to be? If a simple LCG is sufficient, that's trivial to implement in Ruby. Need something more? Check out this thread: Scroll down to the post by George Marsaglia, where he discusses a bit about Mersenne and others, and provides simple C code for an alternative, simpler than Mersenne, and would probably be very easy to translate to Ruby and so have multiple generators.