class Mongoid::Criteria
Public Instance Methods
sample(n = 1)
click to toggle source
# File lib/mongoid/sample.rb, line 6 def sample(n = 1) indexes = (0..count - 1).sort_by { rand }.slice(0, n) if n == 1 skip(indexes.first).first else indexes.map { |i| skip(i).first } end end