Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: inclusive rand

by marioroy (Prior)
on Mar 13, 2017 at 13:38 UTC ( [id://1184420]=note: print w/replies, xml ) Need Help??


in reply to Re^2: inclusive rand
in thread inclusive rand

Unfortunately, Math::Random::Secure's dependencies have many sub-dependencies.

use strict; use warnings; use Math::Random::Secure 'irand'; # Random number between 0 and 1 inclusive (total 524288-1 numbers). sub custom_rand { irand(524288) / 524287; } printf("%f\n", custom_rand()) for 1 .. 20;

Regards, Mario.

Edit: Applied correction. Thanks pryrt.

Replies are listed 'Best First'.
Re^4: inclusive rand
by pryrt (Abbot) on Mar 13, 2017 at 15:28 UTC

    Since irand($n) returns [0,$n) => [0,$n-1] -- ie, not including $n -- you would have to divide by 524287 to get [0,1] inclusive.

      Thank you, pryrt. I applied the correction.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found