Subject: Re: System clock resolution and random numbers
To: Rick Byers <>
From: Greg Troxel <>
List: current-users
Date: 05/01/1997 07:37:13
You probably should look at Ted T'so's /dev/random from Linux, which
is also in FreeBSD.  The resolution of tv_sec is machine-dependent in
ways that may be slightly hard to observe.  In machines without a
cycle counter or usec clock register or in which it is not used in
microtime(), the normal increment might be 10 ms, 1/256s or 1/1024s.
Because of adjtime() from NTP, or because some of the above aren't a
round number of microseconds, the return values may appear to the
casual observer to be much more random than they really are.

You didn't say what your application is, but since you mentioned not
being able to find things out without root access, it sounds like it
might be cryptography.  In that case I'd advise you to stay away from
gettimeofday as your sole source of randomness.

You also didn't way what port you are using, or whether you wish to
write portable code; there is no reason to expect all ports to behave
the same way, since the underlying hardware facilities will differ.