diff options
Diffstat (limited to 'users/wpcarro/scratch/facebook/hard/fisher-yates.py')
-rw-r--r-- | users/wpcarro/scratch/facebook/hard/fisher-yates.py | 7 |
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 000000000000..200d1613ddcb --- /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] |