random.shuffle?
François Pinard
pinard at iro.umontreal.ca
Mon Jul 31 11:32:44 EDT 2000
[Albert Hopkins]
> I wrote a script on my RedHat Linux 6.2 box at home and was pleasantly
> surprised to see that there was a random.shuffle function. However,
> when I later ran the script on my RedHat 6.2 box at work, there was
> no such function. Anyone have any idea where it came from?
No, but it is easily rewritten. Let's see... (untested)
import whrandom
def shuffle(items):
"""Shuffle ITEMS in place. ITEMS should normally be a list."""
for top in range(len(items)-1, 0, -1):
index = whrandom.randint(0, top)
items[index], items[top] = items[top], items[index]
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list