Skip to content

Commit

Permalink
Add badshuffle example
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Mar 25, 2019
1 parent 19b96b5 commit c8db317
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/badshuffle.py
@@ -0,0 +1,24 @@
#!/usr/bin/python3

import random

# "Shuffle" a list, but *wrong*.

narray = 16
a = [0] * narray
h = [0] * narray

for _ in range(10000):
for i in range(narray):
a[i] = i
for i in range(narray):
j = random.randrange(narray)
tmp = a[j]
a[j] = a[i]
a[i] = tmp
for i in range(narray):
if a[i] == narray - 1:
h[i] += 1
break

print(h)

0 comments on commit c8db317

Please sign in to comment.