File: badshuffle.py

package info (click to toggle)
snek 1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,420 kB
  • sloc: ansic: 23,496; python: 4,344; makefile: 1,684; sh: 691; lisp: 2
file content (27 lines) | stat: -rw-r--r-- 455 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python3

from random import *
from time import *

seed(monotonic())

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

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

for _ in range(100000):
    for i in range(narray):
        a[i] = i
    for i in range(narray):
        j = 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)