Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Assignment2pt2
- #Jonathan Dombrowski
- #916921673
- #Jdombrowski416@gmail.com
- import numpy as np
- import matplotlib.pyplot as plt
- numberOfTrials = 10000000
- results = np.zeros((numberOfTrials),dtype=float)
- temp1=0.0
- temp2=0.0
- trialCounter=0
- def fillList():
- for i in range(numberOfTrials):
- global trialCounter
- trialCounter=1
- temp1 = np.random.uniform(0,1)
- temp2 = np.random.uniform(0,1)
- results[i]=recGenerator(temp1,temp2)
- def recGenerator(temp1,temp2):
- global trialCounter
- if(temp1>temp2):
- pass
- else:
- temp1=temp2
- temp2=np.random.uniform(0,1)
- trialCounter+=1
- recGenerator(temp1,temp2)
- return trialCounter
- def findExpectedValue():
- sum =0.0
- for i in range(numberOfTrials):
- sum += results[i]
- return str(sum/numberOfTrials)
- fillList()
- print("Expected number of trials is : "+findExpectedValue())
- plt.hist(results, bins=7,normed=1,cumulative=False,
- rwidth=1,stacked=False,label="dataset 1",log=False)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement