Subject: Re: System clock resolution and random numbers
To: John C. Hayward <John.C.Hayward@wheaton.edu>
From: Rick Byers <rickb@iaw.on.ca>
List: current-users
Date: 04/30/1997 18:36:20
On Wed, 30 Apr 1997, John C. Hayward wrote:

> > I'm working on an application that needs as-random-as-possible values. 
> > I've been using the tv_usec from gettimeofday as the seed.  My question
> > is, what is the resolution of tv_usec?  Is it possible to say that it will
> > only ever be a certain subset of possible values?  I assume it's very
> > difficult to predict the exact value at any given time (because subsequent
> > calls return significantly different values).
> > 
> > Is there any better way to make a random number?  I don't like the idea of
> > having a 32 bit seed because that limits the possible outcomes to 2^32.
> > Has their been any thought into putting a random number generator in the
> > kernel, and are there any patches to do this?  I would think this would be
> > nearly perfect since it would be impossible to find the pattern unless you
> > had root/physical access.

> Use random - it has a larger facility than 2^32 (from man 3 random)
> ===
>      The random() function uses a non-linear additive feedback random number
>      generator employing a default table of size 31 long integers to return
>      successive pseudo-random numbers in the range from 0 to (2**31)-1.
>      The period of this random number generator is very large, approximately
>      16*((2**31)-1).
> ===
> This should be large enough for _any_ application.
> johnh...

I am using random, but the problem isn't with the generator itself, it's
witht the seed.  random() has to be initialized with srandom wich takes a
32 bit seed for an argument.  Same seed, same sequence of random numbers.
I dont understand exactly how initstate() works, so I'm affraid to rely on
it since I have no real way of telling how random the data is (besides
doing billions of samples and comparing them).  Anyone care to comment on
initstate?

Thanks,
	Rick

=========================================================================
Rick Byers                                      Internet Access Worldwide
rickb@iaw.on.ca                                      System Administrator
Welland, Ontario, Canada                                    (905)714-1400
http://www.iaw.on.ca/rickb/                         http://www.iaw.on.ca/