<br><br><div><span class="gmail_quote">On 8/7/07, <b class="gmail_sendername">Alan Gauld</b> &lt;<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>&quot;Bob Gailer&quot; &lt;<a href="mailto:bgailer@alum.rpi.edu">bgailer@alum.rpi.edu</a>&gt; wrote<br><br>&gt; 10000 games would&nbsp;&nbsp;be distributed thus:<br>&gt; 1 = 45 pts<br>&gt; 10 = 30+ pts<br>&gt; 99989 = 15-25 pts
<br>&gt; so generate a random integer between 1 and 10000.<br>&gt; if it is &lt;= 1 then 45<br>&gt; else if it is &lt;= 11 then 30+<br>&gt; else 15-25<br><br>Bob&#39;s approach is typical for large data sets, for small data sets
<br>it can be easier to create a statistically representative sample<br>population then pick on from the population.<br><br>Thus if there are 3 possible outcomes and 1 is twice as likely<br>as 2 which is 4 times as likely as 3 we can create a sample like:
<br><br>pop = [3,2,2,2,2,1,1,1,1,1,1,1,1]<br><br>(List comprehensions, zip and other list building functions can<br>help generate the population sample.)<br><br>Now selecting a single entry from pop will give the right<br>
randomness. This technique has the advantage of a single<br>random selection but it quickly runs out of steam for complex<br>data. In that case Bob&#39;s approach is better but requires two<br>random functions.<br><br>HTH,
<br><br>--<br>Alan Gauld<br>Author of the Learn to Program web site<br><a href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</a><br><br>_______________________________________________
<br>Tutor maillist&nbsp;&nbsp;-&nbsp;&nbsp;<a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br><br>Python provides you with a pseudo random number generator whose output values are uniformly distributed between the input parameters.&nbsp; What you are dealing with in fish weights or test scores or other natural phenomena is most likely a normal distribution. Yes, it&#39;s the bell-shaped curve that your professors use to give you a letter grade from your numeric score on a test.&nbsp; There is an average score or weight called the mean and a measure of the pointedness of the curve called the standard deviation so that two thirds of all the scores are going to be within a standard deviation of that mean.&nbsp; In your catfish example suitable values might be mean = 10 inches with a standard deviation of 4 inches.&nbsp; There are several numerical algorithms that massage a uniformly distributed random value (or several uniformly distributed random values) into a normally distributed random value.&nbsp; Check out Wikipedia&#39;s normal distribution entry.&nbsp; The math is really juicy. You may end up with a recipe for the Python Cookbook.
<br><br>Have fun.<br><br>Steve<br>