One of n lines in a file: Difference between revisions
Content added Content deleted
m (Added Sidef) |
|||
Line 1,796: | Line 1,796: | ||
100372 99661 100264 99644 100180 99748 99718 100205 99714 100494 |
100372 99661 100264 99644 100180 99748 99718 100205 99714 100494 |
||
</pre> |
</pre> |
||
=={{header|Sidef}}== |
|||
{{trans|Perl 6}} |
|||
<lang ruby>func one_of_n(n) { |
|||
var choice |
|||
n.times { |i| |
|||
choice = i if (1 > i.rand) |
|||
} |
|||
choice - 1 |
|||
} |
|||
func one_of_n_test(n = 10, trials = 1_000_000) { |
|||
var bins = [] |
|||
trials.times { |
|||
bins[one_of_n(n)] := 0 ++ |
|||
} |
|||
bins |
|||
} |
|||
say one_of_n_test()</lang> |
|||
{{out}} |
|||
<pre>99838 100843 99696 100078 99973 100350 100054 99495 99540 100133</pre> |
|||
=={{header|Swift}}== |
=={{header|Swift}}== |