One of n lines in a file: Difference between revisions
Content added Content deleted
No edit summary |
(Added XPL0 example.) |
||
Line 2,512: | Line 2,512: | ||
</pre> |
</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}}== |
=={{header|Yabasic}}== |
||
Line 2,537: | Line 2,560: | ||
end</syntaxhighlight> |
end</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |