Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- v = [0]*3
- seed1 = 1987325923
- v[0] = 0x96696996
- v[1] = seed1
- v[2] = 0xb5b5adad
- def rot(x,k):
- return ((x<<k)|(x>>(32-k)))&4294967295
- #the &num is unnecessary in other programing languages
- def rng():
- v[0], v[2], v[1] = rot(v[2],8), rot(v[1],17), v[0]^(~v[1]&v[2])
- return v[1]
- #some randomness tests
- def bucket(iter):
- size = int(iter/2.71828)
- array = [0]*size
- for i in range(0,iter):
- array[rng()%size] += 1
- count = 0
- for i in range(0,size):
- if array[i] > 7 or array[i] == 0:
- count += 1
- if count < size/2.718:
- print("pass")
- else:
- print("fail",count)
- def pi_aprox(iter):
- hits = 0
- for i in range(0,iter):
- x = (rng()&8388607)/(8388608.0)
- y = (rng()&8388607)/(8388608.0)
- pos = x*x+y*y
- if pos < 1.0:
- hits += 1
- hits = hits*4.0/iter
- print(hits)
- def arithmean(iter):
- total = 0.0
- for i in range(0,iter):
- val = rng()
- a = (val&4278190080)>>24
- b = (val&16711680)>>16
- c = (val&65280)>>8
- d = val&255
- total += (a+b+c+d)/4
- print(127.5-total/iter)
- bucket(10000)
- arithmean(10000)
- pi_aprox(10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement