Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/array_consistent_sample.rb

Instance Method Summary collapse

Instance Method Details

#consistent_sample(n = 1, name = '') ⇒ Object


8
9
10
11
12
# File 'lib/array_consistent_sample.rb', line 8

def consistent_sample(n=1, name='')
  seed = ::Digest::SHA1.hexdigest(self.sort.map(&:to_s).join << name).to_i(16)
  prng = ::Random.new(seed)
  self.sort.sample(n, :random => prng)
end