programming-examples/ruby/Algorithms/shuffle_array_in_place.rb
2019-11-15 12:59:38 +01:00

11 lines
184 B
Ruby

def shuffle_array_in_place(arr)
len = arr.length
(0...len).each do |n|
rand_int = rand(n..len)
arr[n], arr[rand_int] = arr[rand_int], arr[n]
end
arr
end