Module: Polyrun::Partition::StableShuffle

Defined in:
lib/polyrun/partition/stable_shuffle.rb

Overview

Deterministic Fisher–Yates shuffle (spec_queue.md).

Class Method Summary collapse

Class Method Details

.call(items, seed) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/polyrun/partition/stable_shuffle.rb', line 7

def call(items, seed)
  rng = Random.new(Integer(seed))
  a = items.dup
  (a.size - 1).downto(1) do |i|
    j = rng.rand(i + 1)
    a[i], a[j] = a[j], a[i]
  end
  a
end