fork download
  1. function monte_carlo_simulation(iterations)
  2. inside_circle = 0
  3. for _ in 1:iterations
  4. x, y = rand(), rand()
  5. if x^2 + y^2 <= 1
  6. inside_circle += 1
  7. end
  8. end
  9. return (inside_circle / iterations) * 4
  10. end
  11.  
  12. iterations = 1_000_000
  13. @time pi_estimate = monte_carlo_simulation(iterations)
  14. println("EstimaciĆ³n de Pi: ", pi_estimate)
  15.  
Success #stdin #stdout 0.48s 214536KB
stdin
Standard input is empty
stdout
  0.061568 seconds (47.30 k allocations: 2.610 MiB, 87.86% compilation time)
Estimación de Pi: 3.141944