Guest User

shuffling

a guest
Jul 16th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.21 KB | None | 0 0
  1. def shuffling(arr = [])
  2.   length = arr.length
  3.   arr.each_with_index do |element, index|
  4.     i = rand(length)     # last element is not inclusive
  5.     arr[index], arr[i] = arr[i], arr[index]
  6.   end
  7.   arr
  8. end
Advertisement
Add Comment
Please, Sign In to add comment