Skip to content

Instantly share code, notes, and snippets.

@moniquelive
Created October 24, 2021 02:56
Show Gist options
  • Save moniquelive/5c4387bffe5a2413fea9f2d36f8c96d4 to your computer and use it in GitHub Desktop.
Save moniquelive/5c4387bffe5a2413fea9f2d36f8c96d4 to your computer and use it in GitHub Desktop.
Manually scramble a vector in python... because why not
from random import randint
v = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def swap(v, f, t):
print(f, t)
v[f] ^= v[t]
v[t] ^= v[f]
v[f] ^= v[t]
def scramble(v):
lv = len(v)
for i in range(lv-1):
swap(v, i, randint(i+1, lv-1))
print(v)
scramble(v)
print(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment