Onionr/src/onionrcrypto/cryptoutils/randomshuffle.py

13 lines
374 B
Python
Raw Normal View History

2019-07-20 00:01:16 +00:00
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