From f6f83fe323ee08e35b71e7d04c0af3ce453c40c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Mon, 5 Dec 2022 19:40:12 +0800 Subject: [PATCH] Replaced "random.randint" with "secrets.randbelow" in the "new_pk" function. --- src/mia_core/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mia_core/utils.py b/src/mia_core/utils.py index aa799c2..aae649a 100644 --- a/src/mia_core/utils.py +++ b/src/mia_core/utils.py @@ -19,8 +19,8 @@ """ import datetime -import random import urllib.parse +from secrets import randbelow from typing import Dict, List, Any, Type, Optional from django.conf import settings @@ -40,7 +40,7 @@ def new_pk(cls: Type[Model]) -> int: The new random ID. """ while True: - pk = random.randint(100000000, 999999999) + pk = 100000000 + randbelow(900000000) try: cls.objects.get(pk=pk) except cls.DoesNotExist: