about summary refs log tree commit diff
path: root/users/wpcarro/scratch/facebook/hard/fisher-yates.py
diff options
context:
space:
mode:
Diffstat (limited to 'users/wpcarro/scratch/facebook/hard/fisher-yates.py')
-rw-r--r--users/wpcarro/scratch/facebook/hard/fisher-yates.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/users/wpcarro/scratch/facebook/hard/fisher-yates.py b/users/wpcarro/scratch/facebook/hard/fisher-yates.py
new file mode 100644
index 0000000000..200d1613dd
--- /dev/null
+++ b/users/wpcarro/scratch/facebook/hard/fisher-yates.py
@@ -0,0 +1,7 @@
+import random
+
+def shuffle(xs):
+    n = len(xs)
+    for i in range(n):
+        j = random.randint(i, n - 1)
+        xs[i], xs[j] = xs[j], xs[i]