<?xml version="1.0" encoding="windows-1252"?>
<node id="1007633" title="Re^3: Random generator fail" created="2012-12-06 13:44:28" updated="2012-12-06 13:44:28">
<type id="11">
note</type>
<author id="272364">
MidLifeXis</author>
<data>
<field name="doctext">
&lt;P&gt;
Let's step through this:
&lt;code&gt;
foreach (1..100) {
    say rand($_);
}
&lt;/code&gt;
When &lt;c&gt;$_&lt;/c&gt; is equal to ...
&lt;ul&gt;
&lt;li&gt;... 1, rand($_) cannot be larger than 1.&lt;/li&gt;
&lt;li&gt;... 2, rand($_) cannot be larger than 2.&lt;/li&gt;
&lt;li&gt;... 3, rand($_) cannot be larger than 3.&lt;/li&gt;
&lt;li&gt;... 4, rand($_) cannot be larger than 4.&lt;/li&gt;
&lt;li&gt;... 5, rand($_) cannot be larger than 5.&lt;/li&gt;
&lt;li&gt;... 6, rand($_) cannot be larger than 6.&lt;/li&gt;
&lt;/ul&gt;
&lt;/P&gt;
&lt;p&gt;Look at one of my [id://1007561|earlier posts] on this thread.  The [doc://rand|documentation for rand] states that &lt;b&gt;&lt;big&gt;&lt;big&gt;&lt;big&gt;&lt;c&gt;0 &lt;= rand($x) &lt; $x&lt;/c&gt;&lt;/big&gt;&lt;/big&gt;&lt;/big&gt;&lt;/b&gt; if $x &gt; 0.  To accomplish what you are trying to do would require that you do this:
&lt;code&gt;
say 1 + rand(99 - 1) for (1..100)
&lt;/code&gt;
In my previous node, MAX = 99 and MIN = 1.  The 1..100 is the number of iterations you wish to use.  If you use &lt;c&gt;rand($_)&lt;/c&gt;, your results will be biased toward the lower end of the counter range.&lt;/p&gt;

&lt;div class="pmsig"&gt;&lt;div class="pmsig-272364"&gt;
&lt;p&gt;--MidLifeXis&lt;/p&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1007396</field>
<field name="parent_node">
1007567</field>
</data>
</node>
