[vox-tech] random number question

vox-tech@lists.lugod.org vox-tech@lists.lugod.org
Wed, 15 May 2002 16:43:38 -0400


Pete,

- Could you explain you want in the way of random numbers?

  (reproducible or not, how many over the life of the program, how long
  the program runs, etc...)


On Wed, May 15, 2002 at 12:16:00PM -0700, Peter Jay Salzman wrote:
> begin msimons@moria.simons-clan.com <msimons@moria.simons-clan.com> 
> > open up the /dev/urandom device and read bytes from there... from read
> > to read you will get randomized stuff.
> 
> 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.

  If there is a need for true random numbers and then /dev/urandom isn't 
bad at all... even for large numbers of fetches.

  Reading is about 25 times slower... but if any significant CPU work being 
done with the random numbers after they are fetched, then the 25 times
slower will be lost in the noise.

    TTFN,
      Mike


  It wouldn't be hard to provide an interface that mimics the srand/rand
interface so that at link time you pick if you want true random or pseudo
random.


Following times on a pentium 100 ...

call rand:
  parent reporting 1048576 randoms fetched in 1.472942 seconds
        Command being timed: "./rand"
        User time (seconds): 1.27
        System time (seconds): 0.01
        Percent of CPU this job got: 85%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.49

/dev/urandom:
  parent reporting 1048576 randoms fetched in 35.903687 seconds
        Command being timed: "./read"
        User time (seconds): 0.01
        System time (seconds): 30.72
        Percent of CPU this job got: 85%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:35.92

/dev/zero:
  parent reporting 1048576 randoms fetched in 0.090543 seconds
        Command being timed: "./zero"
        User time (seconds): 0.01
        System time (seconds): 0.07
        Percent of CPU this job got: 72%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.11