From: Ron Peterson <rpeterso@mtholyoke.edu>
To: linux-kernel@vger.kernel.org
Subject: /dev/random vs. /dev/urandom
Date: Fri, 7 Jan 2005 14:05:36 -0500 [thread overview]
Message-ID: <20050107190536.GA14205@mtholyoke.edu> (raw)
When I compile and run the code below, the string of octal characters
generated by reading /dev/random contains long strings of zeroes. I was
under the impression that /dev/random is "more random" than
/dev/urandom, and will block when it runs out of entropy until it
gathers more. It's only when RAND_LEN is on the largish side that these
strings of zeroes appear.
I'm guessing this behaviour is to be expected; I just don't understand
it.
This is linux kernel 2.6.8.1.
#include <stdio.h>
#include <fcntl.h>
#define RAND_LEN 1024
void
read_random( const char* dev ) {
int i, fd;
char dat[RAND_LEN + 1];
fd = open( dev, O_RDONLY );
dat[RAND_LEN] = '\0';
if( fd != -1 ) {
read( fd, dat, RAND_LEN );
for( i = 0; i < RAND_LEN; i++ ) {
dat[i] = (dat[i] & 0x07) + '0';
}
printf( "%s: %s\n\n", dev, dat );
} else {
exit( 1 );
}
close( fd );
}
int
main( void ) {
read_random( "/dev/random" );
read_random( "/dev/urandom" );
return( 0 );
}
e.g.
$ ./test
/dev/random: 5417351746543663033176215502400146103743161053514107722724572227577211175264555157343736274051424454260000000410000000000477510042000000000042400000100004776700057700000477560000103410000004100000041005777000411040100000000000000000000000000000000000000000000000000000000000000000000000000000411025574400000000000000000000000000000000000000000000100000000046404040000060574400000000010000000000000000000000001000000000000000000000000000000000006200000000000000041041770000077723004040600045770000000000000000000000006000404003400000000000000000000000000000000000000000000000000000000000000000120026302630000000000000473005300320031030000610041045104530477772004530211202304677001010000610000010000000000000001200114000100000041000000140067712002630724000004677000047300530032003103000061004104010324007777200324067710140077700101000061000001000000000000000000000000410470003104777610045100610100000000000077700000000000000006771077706104530023000300310407747770300730070000220417740776210465006504777574046504077041030000610
/dev/urandom: 1655466217206163634777531607666420217322330273327062554377500673762610503232764303737770374066306640130702327235453637234726515320440537063623075347362744022761643031224147437567521545005217571341376634432705100716667264573662535077131060611205546167254244173277374124057015170471752463673753257446324120132341703110113324160500424545414427103452004326607527142023223056654417412072453735343241747171121471174343351366215703670565624370656416102432525141711102001344506103237445351607531346546542130670340524726467315466500144520507166250124000513673351302523654724763452657772702110446526330137221714042445716025510445073154154554433625137743012150647422324104477276471266371157432250425702471733705106524743537622014253265310174041504105572260571526120773547047577667711773160042711607626651223077130635371771754041162573451444327036771052224666641252456167376416110445223405032201545552374202763513507366033462320535502163264137406437201346313404576320371006224721327520444466067703201155645714316637347641311513007645264
Happy New Year!
--
Ron Peterson
Network & Systems Manager
Mount Holyoke College
http://www.mtholyoke.edu/~rpeterso
next reply other threads:[~2005-01-07 19:06 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-07 19:05 Ron Peterson [this message]
2005-01-07 19:16 ` /dev/random vs. /dev/urandom Paulo Marques
2005-01-07 19:24 ` Chris Friesen
2005-01-07 19:26 ` Florian Weimer
2005-01-07 19:27 ` linux-os
2005-01-07 19:40 ` Robert Love
2005-01-07 20:50 ` Ron Peterson
2005-01-07 21:39 ` Andries Brouwer
2005-01-07 22:39 ` linux-os
2005-01-07 17:55 ` Michal Schmidt
2005-01-07 23:29 ` Andries Brouwer
2005-01-08 17:34 ` Patrick J. LoPresti
2005-01-10 12:41 ` linux-os
2005-01-10 13:03 ` Paulo Marques
2005-01-10 14:39 ` Felipe Alfaro Solana
2005-01-10 15:13 ` Patrick J. LoPresti
2005-01-10 19:24 ` David Schwartz
2005-01-11 14:38 ` Andrea Arcangeli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050107190536.GA14205@mtholyoke.edu \
--to=rpeterso@mtholyoke.edu \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).