From 183e6491d0e9cbc18b949ec13d3e796b8ba884fa Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 19 Oct 2020 07:28:38 +0000 Subject: [PATCH] use SystemRandom for randomshuffle instead of own rolled implementation --- src/onionrcrypto/cryptoutils/randomshuffle.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/onionrcrypto/cryptoutils/randomshuffle.py b/src/onionrcrypto/cryptoutils/randomshuffle.py index 05f859fc..64dbf086 100644 --- a/src/onionrcrypto/cryptoutils/randomshuffle.py +++ b/src/onionrcrypto/cryptoutils/randomshuffle.py @@ -1,13 +1,6 @@ -import secrets +from random import SystemRandom + 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 \ No newline at end of file + SystemRandom().shuffle(myList) + return myList \ No newline at end of file