Return to Snippet

Revision: 24690
at March 9, 2010 00:56 by magicrebirth


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

Revision: 24689
at March 9, 2010 00:55 by magicrebirth


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


Initial URL

                                

Initial Description

                                

Initial Title
python\'s random

Initial Tags
textmate, python

Initial Language
Python