One of n lines in a file: Difference between revisions

Updated to work with Nim 1.4: replaced ".. <" with "..<"; replaced "import math" with "import random"; replaced "random(x+1)" with "rand(x)"; updated output.
(Updated to work with Nim 1.4: replaced ".. <" with "..<"; replaced "import math" with "import random"; replaced "random(x+1)" with "rand(x)"; updated output.)
Line 1,445:
 
=={{header|Nim}}==
<lang nim>import mathrandom
randomize()
 
proc oneOfN(n: int): int =
result = 0
for x in 0 .. < n:
if random(x+1) == 0:
result = x
 
Line 1,462:
echo oneOfNTest()</lang>
Output:
<pre>@[99912100454, 100048100110, 9989499882, 9969799733, 99806100171, 10031699724, 100209100111, 9989899874, 100027100159, 10019399782]</pre>
 
=={{header|OCaml}}==
Anonymous user