Skip to content

Instantly share code, notes, and snippets.

@libswan
Created May 11, 2013 13:02
Show Gist options
  • Save libswan/5559906 to your computer and use it in GitHub Desktop.
Save libswan/5559906 to your computer and use it in GitHub Desktop.
import pylab
import random
def LV(numBalls, numTrials):
finalSteps = []
for i in range(numTrials):
ballList = []
steps = 0
for i in range(numBalls):
i = random.choice(['white', 'black'])
ballList.append(i)
#print ballList
for i in range(len(ballList)):
#print i
randomBall = random.choice(ballList)
#print randomBall
if randomBall == 'white':
break
elif randomBall == 'black':
ballList.remove(randomBall)
steps += 1
#print ballList
finalSteps.append(steps)
#print finalSteps
pylab.hist(finalSteps, bins = 11)
#xmin, xmax = pylab.xlim()
#ymin, ymax = pylab.ylim()
#print 'x-range =', xmin, '-', xmax
#print 'y-range =', ymin, '-', ymax
#pylab.xlim(-1.0, 2.0)
pylab.figure(1)
pylab.savefig('LV')
pylab.show()
LV(1000,1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment