One of n lines in a file: Difference between revisions

Content added Content deleted
Line 1,245: Line 1,245:
10 100365
10 100365
</pre>
</pre>

=={{header|Maple}}==
<lang Maple>
with(RandomTools[MersenneTwister]);
one_of_n_lines_in_a_file := proc(fn)
local fid, N, n, L, l, line;
fid := fopen(fn,'READ');
if fid<0 then
return;
end if;
N := 0;
n := 1;
while not feof(fid) do
N := N+1;
L := FileTools[Text][ReadLine](fid);
if (N*GenerateFloat() < 1) then
n := N;
line := L;
end if;
end do;
fclose(fid);
return(n);
end proc;
</lang>




=={{header|Mathematica}}==
=={{header|Mathematica}}==