Guest User

Untitled

a guest
Jan 6th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. total = some very large number
  2. hits = 0
  3.  
  4. for i = 1 to total
  5. u = random()
  6. v = random()
  7. w = random()
  8. if ( u > 0 and abs(v) < 2*u and abs(w) < 2*u ) hits = hits + 1
  9. end
  10.  
  11. fraction = hits/total
  12.  
  13. Inside = 0
  14. Loops = eval(input("Desired times of iteration please?"))
  15. for i in range(Loops):
  16. theta, phi = random()*2*math.pi, random()*2*math.pi
  17. x, y, z = math.sin(theta)*math.cos(phi), math.sin(theta)*math.sin(phi), math.cos(phi)
  18. if abs(y) < 2*x and abs(z) < 2*x:
  19. Inside = Inside + 1
Add Comment
Please, Sign In to add comment