Skip to content

Commit cfc50de

Browse files
committed
use urandom as initial seed
1 parent 33af604 commit cfc50de

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

frameworks/Python/aiohttp/app/random_utils.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# cython: wraparound=False
33
# cython: initializedcheck=False
44

5-
from libc.stdlib cimport rand, srand, calloc, free
6-
from libc.time cimport time
5+
from libc.stdlib cimport calloc, free
76

87
import cython
8+
import os
99

1010
# Constants
1111
cdef unsigned int MAX_VALUE = 10000
@@ -19,8 +19,8 @@ cdef unsigned long seed = 0
1919

2020
cdef void _init_seed():
2121
global seed
22-
srand(<unsigned long>time(NULL))
23-
seed = rand() % MAX_VALUE
22+
cdef bytes random_bytes = os.urandom(4)
23+
seed = int.from_bytes(random_bytes, byteorder='little') % MODULOS
2424

2525
if seed == 0:
2626
seed = 1 # Ensure seed is never zero to avoid low number cycle

0 commit comments

Comments
 (0)