programming-examples/ruby/Algorithms/shuffle_array_in_place.rb

11 lines
184 B
Ruby
Raw Normal View History

2019-11-15 12:59:38 +01:00
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