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

Discussion in 'Perl Misc' started by Michele Dondi, Feb 22, 2004.

  1. 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
    --
    you'll see that it shouldn't be so. AND, the writting as usuall is
    fantastic incompetent. To illustrate, i quote:
    - Xah Lee trolling on clpmisc,
    "perl bug File::Basename and Perl's nature"
    Michele Dondi, Feb 22, 2004
    #1
    1. Advertising

  2. Michele Dondi

    Anno Siegel Guest

    Michele Dondi <> wrote in comp.lang.perl.misc:
    > 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
    Anno Siegel, Feb 22, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Grzegorz Smith

    trying to get hash from os.urandom

    Grzegorz Smith, Jan 23, 2006, in forum: Python
    Replies:
    2
    Views:
    922
    Robert Kern
    Jan 23, 2006
  2. Ron Peterson

    /dev/urandom vs. /dev/random

    Ron Peterson, Jan 7, 2005, in forum: C Programming
    Replies:
    21
    Views:
    1,509
    Keith Thompson
    Jan 13, 2005
  3. gert
    Replies:
    7
    Views:
    614
  4. Mike Boone
    Replies:
    0
    Views:
    144
    Mike Boone
    Dec 22, 2007
  5. VK
    Replies:
    15
    Views:
    1,130
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page