Last active
October 11, 2018 21:34
-
-
Save envil/7ec0577b883426b56d6f46e7cf969007 to your computer and use it in GitHub Desktop.
Monte Carlo Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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