Guest User

Untitled

a guest
Jun 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. class Product
  2. def self.get_random number_of_products = 1
  3. records = []
  4. runaway = 0
  5. while records.size < number_of_products
  6. record = find(:first, :offset => rand(count))
  7.  
  8. if !records.include?(record) && record
  9. records << record
  10. end
  11.  
  12. runaway += 1
  13. break if runaway > number_of_products * 10
  14. end
  15.  
  16. records
  17. end
  18. end
Add Comment
Please, Sign In to add comment