Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Best random number

by bitman (Beadle)
on Dec 19, 2002 at 13:29 UTC ( #221105=perlquestion: print w/replies, xml ) Need Help??
bitman has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone figured out the BEST random number generator? Is it rand or is there a module that members rate?

I currently looking at a hardware solution too (Orion RNG) but the software demos fail on XP, I've written my own to access the serial port but it appears to be flaky (putting it mildly), do you have experience of this widget (and example software (in perl))?

Replies are listed 'Best First'.
Re: Best random number
by Callum (Chaplain) on Dec 19, 2002 at 13:57 UTC

      I agree with Math::TrulyRandom, but since the generation might take a long time, it is best to use this only as a seed generator, and use rand which is pretty reliable.
      Dr. Mark Ceulemans
      Senior Consultant
      IT Masters, Belgium

        use this only as a seed generator, and use rand

        The random seed set by srand is usually 32 bits. If you put 32 bits of randomness in, you cannot expect more than 32 bits of randomness out. Someone might be able to predict the rest of the sequence. That might be good enough, and it might not.

Re: Best random number
by t0mas (Priest) on Dec 19, 2002 at 14:02 UTC
    You could try to get them from The following snippet will print 100 random numbers between 1 and 100.

    They offrer a CORBA interface if HTTP turns you off...
    #!/usr/bin/perl -w use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $response = $ua->get(' +&min=1&max=100&col=1'); if ($response->is_success) { print $response->content; } else { print $response->status_line; }
    Merry Christmas

    /brother t0mas

      I wouldn't trust this solution, since the numbers are being transfered in plaintext. If I'm being really paranoid, I wouldn't even trust the numbers if they were sent over SSL (even if SSL is secure, can still know what numbers I received). Unless you have a special situation, don't send random numbers you need in cryptographic applications over any network, even if you are using encryption.

        If I'm really paranoid, I wouldn't trust a website claiming to generate random numbers. Who says they aren't logging what they send me?


Re: Best random number
by hardburn (Abbot) on Dec 19, 2002 at 14:57 UTC

    It's certainly not rand(). Don't use rand() for anything that needs cryptographic-quality random numbers.

    On some *nix systems, you have /dev/random. Newer Intel (but not AMD, AFAIK) processor's have a hardware RNG in the CPU. Since you mentioned XP, I'm assuming you need a cross-platform solution. You might want to take a look at what GnuPG does.

      It is part of the Intel i8x0 chipsets, not integrated directly into the CPU (afaik). AMD's 768 chipset also has a RNG. These are supposedly seeded based on thermal noise detected by the chip. I've seen these mentioned in kernel config for both Linux and FreeBSD previously, but I'm not sure what level of support exists.
Re: Best random number
by Monky Python (Scribe) on Dec 19, 2002 at 14:33 UTC
    on Linux you can also read from /dev/random or /dev/urandon.


Re: Best random number
by John M. Dlugosz (Monsignor) on Dec 19, 2002 at 20:11 UTC
    You could try Genuine Quantum Randomness. If your hardware RNG is not working, perhaps you really want to address the hardware problem!

    The "BEST" PRNG, since you ask, is yarrow.

    The Win32 function CryptGenRandom claims to be cryptographically quality. I'd use that as one source of entropy around a known implementation. Another thing that works on Windows boxes is to access the cycle counter of the CPU. The least significant bits will be "random" and a good entropy source, checked in your main dispatch loop or something like that.


Re: Best random number
by jdporter (Canon) on Dec 19, 2002 at 22:01 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://221105]
Approved by Tanalis
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2017-04-27 23:23 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (514 votes). Check out past polls.