Jump to content

One of n lines in a file: Difference between revisions

Added XPL0 example.
No edit summary
(Added XPL0 example.)
Line 2,512:
</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,560:
 
end</syntaxhighlight>
 
 
=={{header|zkl}}==
297

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.