(most probably) OT: /dev/random and /dev/urandom

M

Michele Dondi

I apologize in advance for posting this question that I feel is most
probably OT (if it actually is OT). I have this small script:

#!/usr/bin/perl

use strict;
use warnings;

$/=\0x100_000;
open my $fh, '<:raw', '/dev/urandom' or die $!;
print scalar <$fh>;

__END__

If I run it I get:

# ./foo.pl | wc -c
1048576
# ./foo.pl | wc -c
1048576
# ./foo.pl | wc -c
1048576
# ./foo.pl | wc -c
1048576

[ad libitum]

If I change /dev/urandom to /dev/random, then I get:

# ./foo.pl | wc -c
89
# ./foo.pl | wc -c
89
# ./foo.pl | wc -c
89
# ./foo.pl | wc -c
82
# ./foo.pl | wc -c
^[[A

["hangs", had to press CTRL-C]

FWIW I'm running a 2.6.3 kernel. May something be wrong with my system
or am I doing this *in perl* the wrong way?!?


TIA,
Michele
 
A

Anno Siegel

Michele Dondi said:
I apologize in advance for posting this question that I feel is most
probably OT (if it actually is OT). I have this small script:

#!/usr/bin/perl

use strict;
use warnings;

$/=\0x100_000;
open my $fh, '<:raw', '/dev/urandom' or die $!;
print scalar <$fh>;

__END__

If I run it I get:

# ./foo.pl | wc -c
1048576

....as expected.

[...]
If I change /dev/urandom to /dev/random, then I get:

# ./foo.pl | wc -c
89

That behavior is wrong. The only difference in /dev/urandom and /dev/random
is that random may block when it runs out of entropy while urandom continues
to deliver random data of lower quality. Stick to urandom until the other
can be repaired.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top