Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: how to get a 64bit random number with rand() ?

by Anonymous Monk
on Mar 22, 2018 at 18:11 UTC ( [id://1211557]=note: print w/replies, xml ) Need Help??


in reply to Re: how to get a 64bit random number with rand() ?
in thread how to get a 64bit random number with rand() ?

Now if you *add* two rand() values in order, for example, to get a 64-bit random value
You have omitted a little bit of detail that was not omitted in BrowserUk's warning: the context was combining two 32-bit values to obtain a 64-bit value.

Can you please elaborate on how it is possible to ADD two 32-bit numbers — of any origin, not necessarily rand() — and arrive at a value in 64-bit range?

  • Comment on Re^2: how to get a 64bit random number with rand() ?

Replies are listed 'Best First'.
Re^3: how to get a 64bit random number with rand() ?
by bliako (Monsignor) on Mar 22, 2018 at 23:25 UTC

    my point lies somewhere else, but you are correct:

    adding two 32-bit numbers may get you to, at most, a 33-bit number.

    Read that as "add thirty-two 32-bit rands()" (Gaussian distribution) or "multiply two 32-bit rands()" (uniform-product distribution).

    Adding is just one form of combining two values but it's perfect to demonstrate the caveats of "combining" rand()s and that not all forms of "combining" rand()s lead to the desirable effect.

    bliako

      Read that as "add thirty-two 32-bit rands()"
      You sure about that?

      The issue of entropy distilling is a concern for random number generators. Various sources of randomness are mixed into the pool and typically some one-way hashing applied on the output.

      Unless if you're trying to write a PRNG yourself, you don't want to mix anything. The generator is essentially a stream (and implementing such via IO layers is actually very simple.) From a stream, one just consumes characters.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-26 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found