Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: inclusive rand

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


in reply to inclusive rand

Greetings msh210,

There is Math::Random::Secure supporting random integer between x and y inclusive.

Regards, Mario.

Replies are listed 'Best First'.
Re^2: inclusive rand
by msh210 (Monk) on Mar 13, 2017 at 12:50 UTC

    rand also supports something like that. I asked about numbers between 0 and 1. But thanks.

    $_="msh210";$"=$\;@_=@{[split//,uc]}[2,0];$_="@_$\1";$\=$/;++$_[0]for$...1;print lc substr crypt($_,"@_"),1,6

      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.

        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.

      Math::Random::Secure's irand function supports integer between x and y inclusive. Ah yes, that will not work for 0 and 1.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-23 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found