in reply to Re: inclusive rand
in thread inclusive rand

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

Replies are listed 'Best First'.
Re^3: inclusive rand
by marioroy (Prior) on Mar 13, 2017 at 13:38 UTC

    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.

        Thank you, pryrt. I applied the correction.

Re^3: inclusive rand
by marioroy (Prior) on Mar 13, 2017 at 13:11 UTC

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