Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- total = some very large number
- hits = 0
- for i = 1 to total
- u = random()
- v = random()
- w = random()
- if ( u > 0 and abs(v) < 2*u and abs(w) < 2*u ) hits = hits + 1
- end
- fraction = hits/total
- Inside = 0
- Loops = eval(input("Desired times of iteration please?"))
- for i in range(Loops):
- theta, phi = random()*2*math.pi, random()*2*math.pi
- x, y, z = math.sin(theta)*math.cos(phi), math.sin(theta)*math.sin(phi), math.cos(phi)
- if abs(y) < 2*x and abs(z) < 2*x:
- Inside = Inside + 1
Add Comment
Please, Sign In to add comment