If anyone still has any doubts on this, then repeat the experiment several
times taking the sum of two consecutive line numbers returned.  The
distribution of the sums should be Gaussian if the line numbers returned
are random.

The attached plot shows the distribution for 18166 iterations over a 28
line file.

Incidentally, does anyone know if there are Graph packages with fitting
routines written in Perl?

                                cheers, G.

On Tue, 27 Nov 2001, Andy Bach wrote:

> Hi.
>
> Okay, would the maths folk like to offer a helpful explanation?
>
> a
>
> ---------- Forwarded message ----------
>
> Question:
> 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 its correctness.
>
>
>
> --
> The contents of this message are part of the Perl FAQ:
> Please note that "I" below refers to FAQ authors, and *not* Jeff Yoak or Perl FAQ a 
>Day.
>
> Where to get this document [the Perl FAQ]
>    This document is posted regularly to comp.lang.perl.announce and
>    several other related newsgroups. It is available in a variety of
>    formats from CPAN in the /CPAN/doc/FAQs/FAQ/ directory, or on the web
>    at http://www.perl.com/perl/faq/ .
>
> CREDITS
>    When I first began the Perl FAQ in the late 80s, I never realized it
>    would have grown to over a hundred pages, nor that Perl would ever
>    become so popular and widespread. This document could not have been
>    written without the tremendous help provided by Larry Wall and the
>    rest of the Perl Porters.
>
> AUTHOR AND COPYRIGHT INFORMATION
>    Copyright (c) 1997 Tom Christiansen and Nathan Torkington. All rights
>    reserved.
>
>
>
> --
> 162
> ..
>

Attachment: perlrand.png
Description: PNG image

Reply via email to