Re: /dev/urandom vs. /dev/random
From: Chris Croughton (chris_at_keristor.net)
Date: 01/07/05
- Next message: infobahn: "Re: /dev/urandom vs. /dev/random"
- Previous message: Jonathan Burd: "Re: scope resolution operator???????"
- In reply to: Ron Peterson: "/dev/urandom vs. /dev/random"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 7 Jan 2005 17:45:22 +0000
On 7 Jan 2005 09:33:44 -0500, Ron Peterson
<rpeterso@mtholyoke.edu> wrote:
> In the following piece of code, which simply generates a sequence of
> (random) octal codes, I'm surprised by the apparent non-randomness of
> /dev/random. It's not noticeable unless RAND_LENGTH is largish. I was
> under the assumption that /dev/random was "more random" than
> /dev/urandom, and that it would block if it ran out of entropy until it
> got more. Why am I seeing so many zeroes in my output?
For a start, your question is not really C related, it could happen in
any language. Not only is /dev/random device specific but you are also
using POSIX I/O functions (open/read etc.) rather than the C ones.
> read( fd, dat, RAND_LEN );
What is the length read? It is quite possible that read() is returning
when it gets the first byte or few bytes, and the rest of the array is
undefined.
> for( i = 0; i < RAND_LEN; i++ ) {
You are assuming that you know that the whole array was filled. I
suggest that it wasn't.
(I have a reason for suggesting this. I used dd(1) to read a block from
/dev/random into a file. The first time it got 1024 bytes. The next
time it got two, the one after around 30. I'd be pretty sure that dd(1)
is using the same mechanism to read data. That was on Linux kernel
2.2.19...)
Which does make it a sort-of C question, because if you used the C I/O
(fopen, fread etc.) you might find different behaviour. Or perhaps
not...
Chris C
- Next message: infobahn: "Re: /dev/urandom vs. /dev/random"
- Previous message: Jonathan Burd: "Re: scope resolution operator???????"
- In reply to: Ron Peterson: "/dev/urandom vs. /dev/random"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|