Skip to content

Instantly share code, notes, and snippets.

@taylor
Created May 2, 2011 06:28
Show Gist options
  • Select an option

  • Save taylor/951236 to your computer and use it in GitHub Desktop.

Select an option

Save taylor/951236 to your computer and use it in GitHub Desktop.
Some methods for randomizing the processing order for results returned from a DB query
Straight SQL
SELECT * FROM `fax_stats` WHERE (`company` IN ('company123')) ORDER BY random();
ActiveRecord option #1
FaxStat.find(:all, :conditions => "company='company123'", :order => rand())[2];
ActiveRecord option #2
FaxStat.find(:all,:conditions => {:company => ['company123']}).to_ary.shuffle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment