One of n lines in a file: Difference between revisions

(Adding Lua)
Line 1,448:
Output:
<pre>100288 100047 99660 99773 100256 99633 100161 100483 99789 99910</pre>
 
=={{header|Phix}}==
<lang Phix>function one_of_n(integer n)
integer line_num = 1
for i=2 to n do
if rnd()<1/i then
line_num = i
end if
end for
return line_num
end function
 
sequence counts = repeat(0,10)
for i=1 to 1000000 do
counts[one_of_n(10)] += 1
end for
?counts</lang>
{{out}}
<pre>
{99998,100223,99972,100323,100174,99663,99593,100141,99866,100047}
</pre>
 
=={{header|PicoLisp}}==
Line 1,463 ⟶ 1,484:
Output:
<pre>-> (99893 100145 99532 100400 100263 100229 99732 100116 99709 99981)</pre>
 
=={{header|PureBasic}}==
<lang purebasic>Procedure.f randomFloat()
7,796

edits