Skip to content

Instantly share code, notes, and snippets.

@mdshw5
Last active August 29, 2015 13:55
Show Gist options
  • Save mdshw5/8773843 to your computer and use it in GitHub Desktop.
Save mdshw5/8773843 to your computer and use it in GitHub Desktop.
portable replacement for random.choice()
Python 2.7.5 (default, Oct 9 2013, 20:09:30)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.78)] on darwin
>>> x = range(100)
>>> random.seed(1)
>>> print([random.choice(x) for i in range(10)])
[13, 84, 76, 25, 49, 44, 65, 78, 9, 2]
>>> random.seed(1)
>>> print([choice(x) for i in range(10)])
[13, 84, 76, 25, 49, 44, 65, 78, 9, 2]
Python 3.3.3 (default, Jan 1 2014, 15:17:09)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.78)] on darwin
>>> x = range(100)
>>> random.seed(1)
>>> print([random.choice(x) for i in range(10)])
[17, 72, 97, 8, 32, 15, 63, 97, 57, 60]
>>> random.seed(1)
>>> print([choice(x) for i in range(10)])
[13, 84, 76, 25, 49, 44, 65, 78, 9, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment