Constrained random points on a circle: Difference between revisions

→‎{{header|Lua}}: added Lua solution
(Updated to work with version 1.4 of Nim. Used standard library "sample" to get a random element from a sequence. Doubled horizontal scale.)
(→‎{{header|Lua}}: added Lua solution)
Line 2,053:
 
[[File:Points on a circle locomotive basic.png]]
=={{header|Lua}}==
Method 1, modified so that the 100 points must be unique..
<lang lua>t, n = {}, 0
for y=1,31 do t[y]={} for x=1,31 do t[y][x]=" " end end
repeat
x, y = math.random(-15,15), math.random(-15,15)
rsq = x*x + y*y
if rsq>=100 and rsq<=225 and t[y+16][x+16]==" " then
t[y+16][x+16], n = "██", n+1
end
until n==100
for y=1,31 do print(table.concat(t[y])) end</lang>
{{out}}
<pre> ██ ██
██ ████ ██ ██
████ ████ ██
██ ██ ████ ██ ██
██ ████ ██ ██
██ ██ ██ ██
██ ██ ██ ██ ██ ████
██ ████
██ ██
████ ██
██████
██
██ ██ ██
██ ██ ██
██ ██ ██
██
██
██ ██ ██
██
██████
██ ██ ██
████
██ ██
████ ██
████ ██████ ████ ██
██ ████ ██ ██ ██ ██ ██
████ ██ ████
██ ██
██ ████</pre>
 
=={{header|Maple}}==
Anonymous user