in reply to Re^2: Random generator fail
in thread Random generator fail
Let's step through this:
When $_ is equal to ...foreach (1..100) { say rand($_); }
- ... 1, rand($_) cannot be larger than 1.
- ... 2, rand($_) cannot be larger than 2.
- ... 3, rand($_) cannot be larger than 3.
- ... 4, rand($_) cannot be larger than 4.
- ... 5, rand($_) cannot be larger than 5.
- ... 6, rand($_) cannot be larger than 6.
Look at one of my earlier posts on this thread. The documentation for rand states that 0 <= rand($x) < $x if $x > 0. To accomplish what you are trying to do would require that you do this:
In my previous node, MAX = 99 and MIN = 1. The 1..100 is the number of iterations you wish to use. If you use rand($_), your results will be biased toward the lower end of the counter range.say 1 + rand(99 - 1) for (1..100)
--MidLifeXis
In Section
Seekers of Perl Wisdom