Skip to content

Instantly share code, notes, and snippets.

@mdshw5
Created February 2, 2014 20:20
Show Gist options
  • Save mdshw5/8774298 to your computer and use it in GitHub Desktop.
Save mdshw5/8774298 to your computer and use it in GitHub Desktop.
portable choice
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