Skip to content

Instantly share code, notes, and snippets.

@lambdamusic
Created February 7, 2013 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lambdamusic/4734394 to your computer and use it in GitHub Desktop.
Save lambdamusic/4734394 to your computer and use it in GitHub Desktop.
Python: python\'s random
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