Skip to content

Instantly share code, notes, and snippets.

@hnq90
Created July 29, 2015 02:29
Show Gist options
  • Select an option

  • Save hnq90/4cd1f05556a8a2e3aee9 to your computer and use it in GitHub Desktop.

Select an option

Save hnq90/4cd1f05556a8a2e3aee9 to your computer and use it in GitHub Desktop.
def get_random(floor, ceiling):
return random.randrange(floor, ceiling + 1)
def naive_shuffle(the_array):
# for each index in the array
for first_index in xrange(0,len(the_array)-1):
# grab a random other index
second_index = get_random(0, len(the_array)-1)
# and swap the values
the_array[first_index], the_array[second_index] = the_array[second_index], the_array[first_index]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment