Thanks to everyone who replied, (and special thanks to Alex Martelli,) I
was able to accomplish what I originally asked for: a shuffle() which is
both fast and without bias. It is the first time I try to optimize
python code, and it is definitely a very rewarding experience.
To bring closure
By incorporating Alex's code, I got another performance boost of 20%.
It is mostly due to Alex's more efficient implementation of block random
than my own version.
-tooru honda
Below is the code I have now:
from binascii import hexlify
from os import urandom
class
os.urandom account for almost half of the total execution time
for my program. By implementing my own random and getting a much larger
chunk of random bytes from os.urandom each time, I am able to reduce the
total execution time by half.
-tooru honda
P.S. I use python 2.5.1 on MacOSX 10.4.10
number of cards is 416), the
nonuniformity doesn't matter as most of you have already said. Just to
avoid argument from my friend, I am considering writing my own randint
and shuffle methods based on os.urandom() though.
-tooru honda
--
http://mail.python.org/mailman/listinfo/python-list
produces
finitely many possible results, we get modulo bias when the number of
possible results is not divisible by the size of the shuffled list.
1. Does shuffle() produce uniform result ?
2. If not, is there a fast and uniform shuffle() available somewhere ?
Thanks !
-tooru honda
--
http
Hi,
I am a newbie to mac and python.
Is there an easy way to play wav or mp3 sound file ? I used to use
winsound module before switching to mac, but that only works for windows.
Thanks
Tooru
P.S. I am using Mac OSX 10.4.8 and Python 2.5
--
http://mail.python.org/mailman/listinfo/python-list