use SystemRandom for randomshuffle instead of own rolled implementation
parent
3ca05e2390
commit
183e6491d0
|
@ -1,13 +1,6 @@
|
||||||
import secrets
|
from random import SystemRandom
|
||||||
|
|
||||||
def random_shuffle(theList):
|
def random_shuffle(theList):
|
||||||
myList = list(theList)
|
myList = list(theList)
|
||||||
shuffledList = []
|
SystemRandom().shuffle(myList)
|
||||||
myListLength = len(myList) + 1
|
return myList
|
||||||
while myListLength > 0:
|
|
||||||
removed = secrets.randbelow(myListLength)
|
|
||||||
try:
|
|
||||||
shuffledList.append(myList.pop(removed))
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
myListLength = len(myList)
|
|
||||||
return shuffledList
|
|
Loading…
Reference in New Issue