Skip to content

Instantly share code, notes, and snippets.

@nimamehanian
Created February 21, 2013 02:32
Show Gist options
  • Save nimamehanian/5001520 to your computer and use it in GitHub Desktop.
Save nimamehanian/5001520 to your computer and use it in GitHub Desktop.
Shuffle an array's elements, without using Ruby's built-in methods.
class Array
def mixup
length = self.length
while length > 0
length -= 1
break if length == 0
randomIndex = (rand * (length - 1)).floor
self[length], self[randomIndex] = self[randomIndex], self[length]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment