Constrained random points on a circle: Difference between revisions

added Elixir
(added Falcon)
(added Elixir)
Line 597:
* * * *
** </pre>
 
=={{header|Elixir}}==
<lang elixir>
defmodule Random do
def init() do
:random.seed(:erlang.now())
end
def generate_point() do
x = :random.uniform(31) - 16
y = :random.uniform(31) - 16
if 10*10 <= x*x + y*y and x*x + y*y <= 15*15 do
{x, y}
else
generate_point()
end
end
def circle() do
points = for _ <- 1..100, do: generate_point()
for x <- -15..15 do
for y <- -15..15 do
if Enum.member?(points, {x, y}) do
IO.write "x"
else
IO.write " "
end
end
IO.puts ""
end
end
end
 
Random.init()
Random.circle()
</lang>
Example output:
<pre>
xx x
x x x
x x
x x x x x x x
xx x xx x x
x
x x x x
x x xx
x xx xx
xx x x
x
x x
x x x
x x
xxx x
x x x
x x
x x x
x
x x x
x x x
x x
x xx
x x x x xx
xxx x x
x x x x
x x x
xx x
</pre>
 
=={{header|Euphoria}}==
Anonymous user