Skip to content

Instantly share code, notes, and snippets.

@pablohildo
Created January 16, 2018 02:37
Show Gist options
  • Save pablohildo/e85bd4561c67516f6aa95605071c43f3 to your computer and use it in GitHub Desktop.
Save pablohildo/e85bd4561c67516f6aa95605071c43f3 to your computer and use it in GitHub Desktop.
Fisher and Yates Shuffle Algorithm
def fisher_yates_shuffle(array)
n = array.length
while n > 0
i = rand(n-=1)
array[i], array[n] = array[n], array[i]
end
return array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment