in reply to inclusive rand

Here is one way to do it:

my $precision = 8; for (0..20) { my $var = int(rand($precision)); print $var/($precision-1), "\n"; }
Even if the output of rand is not an int, it still is one value among a list of possible ones. Here that fact is explicit rather than implicit, and you get to chose the size of that list.

Maybe Crypt::Random would be a better fit, since you provide a length in bits for the random number, you just have to map 0 to 0, and ~0 to 1 (ie, divide the big unsigned int by the max value).

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

    Thanks. I guess your code would work if I knew what precision rand uses: I could then use that as $precision.

    The other idea looks worth looking into; thanks much.

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