Perlfaq5 (seen via http://cvs.perl.org/cgi/cvsweb.cgi/perlfaq/ ) says:

<<
=head2 How do I select a random line from a file?

Here's an algorithm from the Camel Book:

     srand;
     rand($.) < 1 && ($line = $_) while <>;

This has a significant advantage in space over reading the whole
file in.  A simple proof by induction is available upon
request if you doubt the algorithm's correctness.
 >>

This "upon request" business is an annoyance.  It should be replaced by 
either the "simple proof", or a URL to the simple proof (neither of which I 
have on hand, or I would supply a patch).


--
Sean M. Burke    [EMAIL PROTECTED]    http://www.spinn.net/~sburke/

Reply via email to