Constrained random points on a circle: Difference between revisions

Updated to work with version 1.4 of Nim. Used standard library "sample" to get a random element from a sequence. Doubled horizontal scale.
(add lambdatalk)
(Updated to work with version 1.4 of Nim. Used standard library "sample" to get a random element from a sequence. Doubled horizontal scale.)
Line 2,134:
=={{header|Nim}}==
{{trans|Python}}
<lang nim>import tables, math, strutils, complex, random
 
proc random[T](a: openarray[T]): T =
result = a[rand(low(a)..len(a))]
 
type Point = tuple[x, y: int]
Line 2,146 ⟶ 2,143:
for x in -15..15:
for y in -15..15:
if abs(complex(x.float, y.float)) in 10.0..15.0:
possiblePoints.add((x,y))
 
randomize()
for i in 0..100: world.inc possiblePoints.randomsample
 
for x in -15..15:
Line 2,156 ⟶ 2,153:
let key = (x, y)
if key in world and world[key] > 0:
stdout.write ' ' & $min(9, world[key])
else:
stdout.write '" ' "
echo ""</lang>
 
Output:
{{out}}
<pre> 1
<pre> 1211 1
1 1 1
1 1 3 1 1
1 1 1 1 3 11
1 2 1 11 1 1 1 1
122 21 1 2
1 1 1 1 1 1
1 1 2
1 1 1 1
1 2 1
11 1 11 1
1 1 1 1
1 1 1
11 1 1 1
1 1 11 1
21 1 1 1 1 1
1 1
1 1
1 1 2
1 1 11 2
1 11 1
1 1 1 1 111 1
1 1 1 1
1 2 2 11 1 1
1 1 1 1 1
12 2 11 1 1 1
1 1 1 1 1
11 1 1
1 1 2 1 1 2 </pre>
1 1 1 1
<pre> 1 1 </pre>
 
=={{header|OCaml}}==
Anonymous user