Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

64 bit random numbers

by Digsy (Initiate)
on Oct 30, 2000 at 19:29 UTC ( [id://39080]=perlquestion: print w/replies, xml ) Need Help??

Digsy has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know how to produce 64bit random numbers ?

Apparently rand() doesnt go this big :-(

I have been told that I need a "special" random number generator to do this.

Couldnt I just create 64 random numbers and put them together ?

Does anyone have any ideas ?

Replies are listed 'Best First'.
Re: 64 bit random numbers
by Fastolfe (Vicar) on Oct 30, 2000 at 19:37 UTC
    Check out Crypt::Random, which will fetch you an arbitrary amount of random data. You may have to pack this into a number if you need a number.

    In a pinch, yah I don't see any reason why you couldn't just take 8 8-bit numbers or 4 16-bit numbers or 2 32-bit numbers, shift appropriately, and add them together. I'm not sure what you mean by 64 random numbers, unless you mean 64 random numbers in the range of 0 .. 1, shifting each one 1 bit over and adding the next. That seems like it would be a little inefficient.

Re: 64 bit random numbers
by neophyte (Curate) on Oct 30, 2000 at 19:45 UTC
RE: 64 bit random numbers
by atl (Pilgrim) on Oct 30, 2000 at 20:14 UTC
    Howdy!

    Digsy asked:
    Couldnt I just create 64 random numbers and put them together ?

    Depends on what you need the random numbers for. Just shuffling the songs for your tremendous mp3 collection? Your suggestion might do fine then (albeit slow), almost anything will. If it's for security purposes (read: encryption and so on), you need the real thing. I think the suggested Math:: and Crypt:: modules will be right (didn't check the docs, though).

    Also, getting a good noise source to seed your random number generator is kind of tricky and OS dependent, if I remember a talk about GPG correctly. (GNU Privacy Guard, an open (who'd thought that!?) PGP replacement).

    Have fun ...

    Andreas

Re: 64 bit random numbers
by elwarren (Priest) on Oct 30, 2000 at 19:53 UTC
    I just compiled perl 5.6 on linux last night. One of the options I noticed was compiling for 64bit platforms. I'm not sure if this is required, but you might want to look at what build you're running with. Might be helpful.

    Now back to the people that know what they're talking about...
Re: 64 bit random numbers
by jdhedden (Deacon) on Jul 07, 2005 at 16:56 UTC
    Provided your Perl was compiled using 'use64bitint', then you can do the following:
    my $rand64 = (int(rand(4294967296)) << 32) | int(rand(4294967296));
    However, Math::Random::MT::Auto provides random 64-bit integers directly (again, provided your Perl is compiled using 'use64bitint'). Just install it from CPAN, and then:
    use Math::Random::MT::Auto qw/irand/; my $rand64 = irand();
    A lot simpler. Plus, the speed is about the same on Windows, and is a lot faster on Solaris.

    Remember: There's always one more bug.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://39080]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-23 19:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found