Monte Carlo methods: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: elided one too many hyphens.) |
(→{{header|Elixir}}: change :random -> :rand module) |
||
Line 398: | Line 398: | ||
<lang elixir>defmodule MonteCarlo do |
<lang elixir>defmodule MonteCarlo do |
||
def pi(n) do |
def pi(n) do |
||
:random.seed(:os.timestamp) |
|||
count = Enum.count(1..n, fn _ -> |
count = Enum.count(1..n, fn _ -> |
||
x = : |
x = :rand.uniform |
||
y = : |
y = :rand.uniform |
||
:math.sqrt(x*x + y*y) <= 1 |
:math.sqrt(x*x + y*y) <= 1 |
||
end) |
end) |