One of n lines in a file: Difference between revisions

Added Easylang
No edit summary
(Added Easylang)
 
(2 intermediate revisions by 2 users not shown)
Line 604:
=={{header|Delphi}}==
See [https://rosettacode.org/wiki/One_of_n_lines_in_a_file#Pascal Pascal].
=={{header|EasyLang}}==
{{trans|Lua}}
<syntaxhighlight>
n = 10
trials = 1000000
func one n .
for i = 1 to n
if randomf < 1 / i
chosen = i
.
.
return chosen
.
len results[] n
for i = 1 to trials
r = one n
results[r] += 1
.
print "Value Occurrences"
print "-------------------"
for i to n
print i & "\t" & results[i]
.
</syntaxhighlight>
 
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
Line 2,475 ⟶ 2,500:
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
import "./fmt" for Fmt
 
var rand = Random.new()
Line 2,512 ⟶ 2,537:
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang "XPL0">func One_of_n(N);
int N, Choice, Line;
[Choice:= 1;
for Line:= 2 to N do
if Ran(1_000_000) < 1_000_000/Line then Choice:= Line;
return Choice;
];
 
int Counters(1+10), I, N;
[for I:= 1 to 10 do Counters(I):= 0;
for I:= 1 to 1_000_000 do
[N:= One_of_n(10);
Counters(N):= Counters(N)+1;
];
for I:= 1 to 10 do
[IntOut(0, Counters(I));
ChOut(0, ^ );
];
]</syntaxhighlight>
{{out}}
<pre>
99477 99885 99826 100174 99902 99766 100287 100125 100386 100172 </pre>
 
=={{header|Yabasic}}==
Line 2,537 ⟶ 2,585:
 
end</syntaxhighlight>
 
 
=={{header|zkl}}==
2,063

edits