Skip to content

Instantly share code, notes, and snippets.

@envil
Last active October 11, 2018 21:34
Show Gist options
  • Save envil/7ec0577b883426b56d6f46e7cf969007 to your computer and use it in GitHub Desktop.
Save envil/7ec0577b883426b56d6f46e7cf969007 to your computer and use it in GitHub Desktop.
Monte Carlo Sort
import numpy as np
'''
This's a just a stupid example with the sole purpose of
demonstrating the Monte Carlo randomization strategy
'''
A = np.random.randint(0, 10000, 1000)
for x in range(1000000):
first_position = np.random.randint(0, 1000)
second_position = np.random.randint(0, 1000)
if A[first_position] > A[second_position] and first_position < second_position:
temp = A[first_position]
A[first_position] = A[second_position]
A[second_position] = temp
print(A)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment