Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Random data from db

by JavaFan (Canon)
on Mar 01, 2012 at 11:03 UTC ( [id://957169]=note: print w/replies, xml ) Need Help??


in reply to Random data from db

Untested:
my $dbh = ... get handle to database ...; my $sth = $dbh->prepare("SELECT * FROM TABLE"); $sth->execute; my @buffer; my $seen; while (my $row = $sth->selectrow_arrayref) { $seen++; if (@buffer < 100) { push @buffer, $row; next; } my $index = int rand $seen; if ($index < @buffer) { $buffer[$index] = $row; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://957169]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-12 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found