2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,9 +1,6 @@
|
|||
defmodule Random do
|
||||
def init() do
|
||||
:random.seed(:erlang.now)
|
||||
end
|
||||
def randN(n) do
|
||||
if :random.uniform(n) == 1, do: 1, else: 0
|
||||
if :rand.uniform(n) == 1, do: 1, else: 0
|
||||
end
|
||||
def unbiased(n) do
|
||||
{x, y} = {randN(n), randN(n)}
|
||||
|
|
@ -12,9 +9,9 @@ defmodule Random do
|
|||
end
|
||||
|
||||
IO.puts "N biased unbiased"
|
||||
Random.init
|
||||
m = 10000
|
||||
for n <- 3..6 do
|
||||
xs = for _ <- 1..10000, do: Random.randN(n)
|
||||
ys = for _ <- 1..10000, do: Random.unbiased(n)
|
||||
IO.puts "#{n} #{Enum.sum(xs) / Enum.count(xs)} #{Enum.sum(ys) / Enum.count(ys)}"
|
||||
xs = for _ <- 1..m, do: Random.randN(n)
|
||||
ys = for _ <- 1..m, do: Random.unbiased(n)
|
||||
IO.puts "#{n} #{Enum.sum(xs) / m} #{Enum.sum(ys) / m}"
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue