[vox-tech] random number question

Peter Jay Salzman vox-tech@lists.lugod.org
Wed, 15 May 2002 12:16:00 -0700


hi mike,

i've been writing down everything i know about random numbers with C.
thanks for the info!   i hope to have something useful in a day or so.

begin msimons@moria.simons-clan.com <msimons@moria.simons-clan.com> 
> 
>   Sometimes is very valuable to be able to have pseudo-random numbers
> which can re-generate a certain sequence of numbers: this is because if 
> your program uses "rand" and crashes sometimes, you can set the seed
> value to some constant number that you know leads to a crash then rerun
> a few times with gdb to figure out what is going wrong...
 
i was able to track down an "off by one" error in my code using this
technique a few weeks ago.  it was non-fatal, and i had no idea where
the bad numbers were coming from.  saving the seed was VERY useful.
 
>   As I said to Mark last time stuff about rand/random came up.  If
> you want lots of non-reproducible random numbers you should open
> up the /dev/urandom device and read bytes from there... from read to
> read you will get randomized stuff.  If you are doing something
> cryptographically sensitive then open /dev/random, but don't try to
> read much data from that device it will block readers until it
> has enough "collected entropy"...

i remember, but reading a file is fine for setting a seed (that's what i
do) but for generating a random number, it can be unsuitable.  a monte
carlo simulation needs between 100,000 and 100,000,000 random numbers.
reading a file for all those numbers would be prohibitive.

pete