Last active
August 29, 2015 13:55
-
-
Save mdshw5/8773843 to your computer and use it in GitHub Desktop.
portable replacement for random.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
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] |
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
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