using /dev/random

Kris Kennaway kris at FreeBSD.org
Thu Sep 25 19:33:18 UTC 2008


RW wrote:
> On Tue, 23 Sep 2008 11:52:07 -0400
> Lowell Gilbert <freebsd-questions-local at be-well.ilk.org> wrote:
> 
>> Robert Huff <roberthuff at rcn.com> writes:
>>
>>> 	What is the canonical way to get data from /dev/random?
>>> Specifically: having opened the file, how do I read the stream?
>>> I'm currently using
>>>
>>>
>>>   union {
>>>     float f;
>>>     char c[4];
>>>   } foo;
>>>
>>>   foo.f = 0.0;
>>>
>>>   fscanf(rand_fp,"%4c",foo.c);
>>>
>>>
>>> 	which doesn't seem to produce anywhere near "random bytes"
>>> as promised by the man page.
>> Have you turned off the "seeded" variable?  You'll fall back to a
>> software pseudorandom sequence if you don't.
> 
> kern.random.sys.seeded is just a flag that gets set to 1 on each
> reseed. IIRC it's also initialized to 1 so it doesn't actually do
> anything very useful.

Except tell you that the kernel random number generator has finished 
seeding ;)

Kris


More information about the freebsd-questions mailing list