Monte Carlo methods: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added a true link to the post output section.) |
(Updated to work with Nim 1.4: added missing parameter type, added "import random", changed "random" to "rand".) |
||
Line 1,721: | Line 1,721: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
<lang nim>import math |
<lang nim>import math, random |
||
randomize() |
randomize() |
||
proc pi(nthrows): float = |
proc pi(nthrows: float): float = |
||
var inside = 0 |
var inside = 0.0 |
||
for i in 1..int64(nthrows): |
for i in 1..int64(nthrows): |
||
if hypot( |
if hypot(rand(1.0), rand(1.0)) < 1: |
||
inside += 1 |
|||
result = 4 * inside / nthrows |
|||
for n in [10e4, 10e6, 10e7, 10e8]: |
for n in [10e4, 10e6, 10e7, 10e8]: |
||
echo pi(n)</lang> |
echo pi(n)</lang> |