lambdamusic
2/7/2013 - 9:27 PM

Python: python\'s random

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)))