[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Random lines from a File



On Thu, 4 Mar 1999, Chris Nandor wrote:
> It is an adaptation of the entry in the FAQ and Cookbook.  I don't fully
> understand it, so don't ask me.  :)


Don't know about in the FAQ, but there is a nice explanation
in the Cookbook if anyone cares to read it...

Something like the first line has a 1/1 probability of being
selected. Then the second has a 1/2 probability of replacing
the previously selected line. ...the nth line has a 1/n
probability of replacing the currently selected line at that
point.

...the math works out that each line has an equal chance by
the end of n lines.

$. is the current $INPUT_LINE_NUMBER

-matt



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org