Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # paulogp
- import random
- import math
- def pi_mc(n=10000):
- '''
- Valor de Pi usando o Metodo de Monte Carlo
- n: numero de "sementes"
- '''
- count_inside = 0
- for count in range(0, n):
- #math.hypot: distancia Euclidiana, sqrt(x*x + y*y)
- d = math.hypot(random.random(), random.random())
- if d < 1: count_inside += 1
- count += 1
- print 4.0 * count_inside / count
- pi_mc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement