Dick Moores wrote:
> Here are the suggestions I've received:
<snipped>

> 
> All 3 are essentially the same, aren't they. Which makes me feel even 
> dumber, because I don't understand any of them. I've consulted 3 
> books, and still don't understand the use of yield.

Yes, they are pretty much the same. Mine is bare-bones, just doing what 
you specifically asked for. Danny's is a full replacement for xrange(); 
Andrei's is in between.

Here is a good introduction to generators:
http://www.python.org/doc/2.2.3/whatsnew/node5.html

> I've realized now that all 3 scripts require an immense number of 
> calls to random()

Um, yeah, more than 2**31-1, right? :-)

By the way your approach to testing the 'goodness' of random() is pretty 
naive. For example a random() that just repeats 0...99 over and over 
would score very well. For large repeat counts it could even repeat the 
same number for a while and score well: 1111111112222222233333333 etc. 
You might be interested in this article and the links at the bottom:
http://en.wikipedia.org/wiki/Pseudo-random_number_generator

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to