Created
February 2, 2014 20:20
-
-
Save mdshw5/8774298 to your computer and use it in GitHub Desktop.
portable choice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def choice(seq): | |
"""Choose a random element from a non-empty sequence. | |
This function produces consistent results from Python2.7 to 3.3 | |
in contrast to random.choice(). """ | |
return seq[int(random.random() * len(seq))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment