Onionr/onionr/onionrcrypto/cryptoutils/randomshuffle.py
2019-07-19 19:01:16 -05:00

13 lines
374 B
Python

import secrets
def random_shuffle(theList):
myList = list(theList)
shuffledList = []
myListLength = len(myList) + 1
while myListLength > 0:
removed = secrets.randbelow(myListLength)
try:
shuffledList.append(myList.pop(removed))
except IndexError:
pass
myListLength = len(myList)
return shuffledList