Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def shuffling(arr = [])
- length = arr.length
- arr.each_with_index do |element, index|
- i = rand(length) # last element is not inclusive
- arr[index], arr[i] = arr[i], arr[index]
- end
- arr
- end
Advertisement
Add Comment
Please, Sign In to add comment