Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,22 @@
defmodule Random do
def init() do
:random.seed(:erlang.now())
end
def randN(n) do
if Enum.member?(3..6, n) do
if :random.uniform(n) == 1, do: 1, else: 0
end
end
def unbiased(n) do
{x, y} = {randN(n), randN(n)}
if x != y, do: x, else: unbiased(n)
end
end
IO.puts "N biased unbiased"
Random.init()
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)}"
end