Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. import numpy as np
  2. import time
  3. start = time.time()
  4.  
  5. N_C = 0.0
  6. n = 99998
  7.  
  8. for x in range(0, n):
  9.  
  10. x2 = np.random.rand()**2
  11. y2 = np.random.rand()**2
  12.  
  13. if ((x2 + y2)**0.5) < 1.0:
  14. N_C += 1
  15.  
  16. mypi = (float(N_C) / n) * 4
  17.  
  18. print(mypi)
  19.  
  20. print(np.pi)
  21.  
  22. end = time.time()
  23. elapsed_time = end - start
  24. print('Time Taken: ', elapsed_time,'seconds')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement