use SystemRandom for randomshuffle instead of own rolled implementation

master
Kevin Froman 2020-10-19 07:28:38 +00:00
parent 3ca05e2390
commit 183e6491d0
1 changed files with 4 additions and 11 deletions

View File

@ -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