[Catalyst] Random

Matt S Trout dbix-class at trout.me.uk
Fri Nov 4 18:22:10 CET 2005


On Fri, Nov 04, 2005 at 08:42:37AM -0800, Will Smith wrote:
> Hi, could someone help me out. :
> I want to randomly get data out of a table and push that to a template. I have checked the source of cpan, there are more than enough modules to do that, but just not sure which one is the right one.

my $source_resultset = $c->comp('M::DBIC')->table('tbl_name')->search(
                         \%cond, { rows => 1 });

my $rand_no = int(rand($source_resultset->count)) + 1;

my $rand_rec = $source_resultset->page($rand_no)->next;

-- 
     Matt S Trout       Specialists in Perl consulting, web development, and
  Technical Director    UNIX/Linux systems architecture and automation. Mail
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list