Use random.choices instead of random.choice in a loop.

This commit is contained in:
voussoir 2021-08-09 08:46:59 -07:00
parent e5f2f6992b
commit 5dae9ba178
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -1381,8 +1381,7 @@ class PDBUserMixin:
''' '''
length = self.config['id_length'] length = self.config['id_length']
for retry in range(20): for retry in range(20):
user_id = (random.choice(constants.USER_ID_CHARACTERS) for x in range(length)) user_id = ''.join(random.choices(constants.USER_ID_CHARACTERS, k=length))
user_id = ''.join(user_id)
user_exists = self.sql_select_one('SELECT 1 FROM users WHERE id == ?', [user_id]) user_exists = self.sql_select_one('SELECT 1 FROM users WHERE id == ?', [user_id])
if user_exists is None: if user_exists is None: