One of n lines in a file: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) m (→{{header|11l}}) |
(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: | Line 1,445: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
<lang nim>import |
<lang nim>import random |
||
randomize() |
randomize() |
||
proc oneOfN(n: int): int = |
proc oneOfN(n: int): int = |
||
result = 0 |
result = 0 |
||
for x in 0 .. |
for x in 0 ..< n: |
||
if random(x |
if random(x) == 0: |
||
result = x |
result = x |
||
Line 1,462: | Line 1,462: | ||
echo oneOfNTest()</lang> |
echo oneOfNTest()</lang> |
||
Output: |
Output: |
||
<pre>@[ |
<pre>@[100454, 100110, 99882, 99733, 100171, 99724, 100111, 99874, 100159, 99782]</pre> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |