Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import numpy as np
- class PickRandom():
- def RandSum1(self):
- s=0
- a = np.array([])
- while(s < 1):
- a = np.append(a,np.random.rand())
- s = np.sum(a)
- return len(a)
- def NumAve(self,n):
- N = np.arange(n)
- l=np.array([])
- for idx,item in enumerate(N):
- l = np.append(l,self.RandSum1())
- return np.mean(l)
- n = 10000 # number of times to select the set of random numbers > 1
- print("number e =",PickRandom().NumAve(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement