Created
February 7, 2013 21:27
-
-
Save lambdamusic/4734394 to your computer and use it in GitHub Desktop.
Python: python\'s random
This file contains hidden or 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
from random import * | |
for x in range(10): | |
print random() | |
print '=============================' | |
z = ['ciao', 'piccolo', 'bambino', 'sono', 'qua', 'io', 'in verita'] | |
for x in z: | |
# picks a random el from a list | |
print choice(z) | |
print '=============================' | |
# "Two ways to randomly attach elements" | |
for x in range(10): | |
shuffle(z) # shuffle modifies the element in place so you have to call it beforehand | |
print " ".join(z) | |
# an alternative method | |
print '=============================' | |
for x in range(10): | |
print " ".join(sample(z, len(z))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment