in reply to inclusive rand
Here is one way to do it:
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.my $precision = 8; for (0..20) { my $var = int(rand($precision)); print $var/($precision-1), "\n"; }
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 |