At 2002-06-02 00:41:01 (-0700), Jeff Zucker wrote:

>   my $ids = $dbh->selectcol_arrayref("
>       SELECT quoteID
>         FROM quotes
>   ");
>   my $random_id = $$ids[ rand(@$ids) ];
[...]

This one can be memory hungry -- especially for large sets.

There is a well-known algorithm on how to get a random row out of
n rows with O(n) and low memory usage.  

> Ilya, does this belong in a FAQ?

perldoc -q "How do I select a random line from a file"

-Wolfgang

Reply via email to