Method: Rex::Text.shuffle_a

Defined in:
lib/rex/text.rb

.shuffle_a(arr) ⇒ Array

Performs a Fisher-Yates shuffle on an array

Modifies arr in place

Parameters:

  • arr (Array)

    The array to be shuffled

Returns:

  • (Array)


1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
# File 'lib/rex/text.rb', line 1555

def self.shuffle_a(arr)
  len = arr.length
  max = len - 1
  cyc = [* (0..max) ]
  for d in cyc
    e = rand(d+1)
    next if e == d
    f = arr[d];
    g = arr[e];
    arr[d] = g;
    arr[e] = f;
  end
  return arr
end