<br><br><div><span class="gmail_quote">On 8/7/07, <b class="gmail_sendername">Alan Gauld</b> <<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>> 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>"Bob Gailer" <<a href="mailto:bgailer@alum.rpi.edu">bgailer@alum.rpi.edu</a>> wrote<br><br>> 10000 games would be distributed thus:<br>> 1 = 45 pts<br>> 10 = 30+ pts<br>> 99989 = 15-25 pts
<br>> so generate a random integer between 1 and 10000.<br>> if it is <= 1 then 45<br>> else if it is <= 11 then 30+<br>> else 15-25<br><br>Bob'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'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 - <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. What you are dealing with in fish weights or test scores or other natural phenomena is most likely a normal distribution. Yes, it's the bell-shaped curve that your professors use to give you a letter grade from your numeric score on a test. 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. In your catfish example suitable values might be mean = 10 inches with a standard deviation of 4 inches. There are several numerical algorithms that massage a uniformly distributed random value (or several uniformly distributed random values) into a normally distributed random value. Check out Wikipedia's normal distribution entry. The math is really juicy. You may end up with a recipe for the Python Cookbook.
<br><br>Have fun.<br><br>Steve<br>