in reply to
Random generator fail
But always get between 0 and 1. Any ideas?
Works as designed.
$ perl -e 'use 5.10.0; say int(6*rand())+1 foreach(1..10);'
Is that what you were after? Or at least something like it?
As MidLifeXis pointed out:
rand Returns a random fractional number greater than or equa
+l to 0
and less than the value of EXPR. (EXPR should be posit
If EXPR is omitted, the value 1 is used. Currently EXP
the value 0 is also special-cased as 1 (this was undocu
before Perl 5.8.0 and is subject to change in future ve
of Perl). Automatically calls "srand" unless "srand" h
already been called. See also "srand".
Apply "int()" to the value returned by "rand()" if you
random integers instead of random fractional numbers.
returns a random integer between 0 and 9, inclusive.
(Note: If your rand function consistently returns numbe
are too large or too small, then your version of Perl w
probably compiled with the wrong number of RANDBITS.)
"rand()" is not cryptographically secure. You should n
on it in security-sensitive situations. As of this wri
number of third-party CPAN modules offer random number
generators intended by their authors to be cryptographi
secure, including: Math::Random::Secure,
Math::Random::MT::Perl, and Math::TrulyRandom.
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg