[Tutor] Workaround for limitation in xrange()?
kent37 at tds.net
Tue Oct 10 20:34:46 CEST 2006
Dick Moores wrote:
> Here are the suggestions I've received:
> 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:
> 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:
More information about the Tutor