Date: Tue, 23 Sep 2008 15:51:33 -0000 From: Lowell Gilbert <freebsd-questions-local@be-well.ilk.org> To: Robert Huff <roberthuff@rcn.com> Cc: questions@freebsd.org Subject: Re: using /dev/random Resent-Message-ID: <44k5d2rikb.fsf@be-well.ilk.org> In-Reply-To: <18648.30321.369520.631459@jerusalem.litteratus.org> (Robert Huff's message of "Tue\, 23 Sep 2008 00\:54\:09 -0400") References: <18648.30321.369520.631459@jerusalem.litteratus.org>
| previous in thread | raw e-mail | index | archive | help
Robert Huff <roberthuff@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.
Most computers don't have all that much real random data ("entropy") to
work with, and if you need a lot of random data, you're more or less
forced to use a good pseudorandom generator. "Good" can vary a bit
depending on application, but random(3) is generally more than good
enough for monte carlo style simulation purposes.
Cryptography is another story. I have a hardware random number
generator on my server, which helps with performance in some cases...
--
Lowell Gilbert, embedded/networking software engineer, Boston area
http://be-well.ilk.org/~lowell/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?>
