From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2003-01-21T12:55:13+09:00 Subject: redefining rand and srand A couple of questions: 1) how good is Ruby's rand function (what's the quality of randomness)? I suspec that it is just the same as C's rand, so there won't be a difference. 2) I'd like to plug in my own random number generator that would probably produce higher-quality random numbers than the current rand does. I'm pretty sure it should be doable and easy, like: module Kernel def rand(max=0) #do random number generation magic here end end But what about overriding srand(num)? srand seeds the random number generator, so I'm assuming there is some module variable that gets set by srand and which rand uses as well... So I figure the way to do it is something like: module Kernel def rand(max=0) generate_random(@seed) end def srand(seed=nil) if not seed #generate @seed using combiation of time, process id and sequence# else @seed = seed end end end ....however I'm guessing that I wouldn't have to redefine srand if I could find the name of the module variable being used. I tried @seed, but it wasn't it.... Kernel.instance_variables didn't help either. Phil -- "Or perhaps the truth is less interesting than the facts?" Amy Weiss (accusing theregister.co.uk of engaging in 'tabloid journalism') Senior VP, Communications Recording Industry Association of America