Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(96)

Side by Side Diff: Python/hash.c

Issue 13704: Random number generator in Python core
Patch Set: Created 8 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #include "Python.h"
2 #include "pyrandom.h"
3
4 Py_hash_t Py_RndHashSeed = -1;
gregory.p.smith 2012/01/15 02:18:38 This should be a Py_uhash_t and the default value
5
6 void
7 _Py_InitRndHashSeed(void)
8 {
9 static int initialized = 0;
10 int result;
11 if (initialized) {
12 return;
13 }
14 initialized = 1;
15
16 result = PyOS_URandom((unsigned char*)&Py_RndHashSeed, sizeof(Py_hash_t));
17 /* fall back to Mersenne twister */
18 if (result == -1) {
19 _Py_MT_RandomState state;
20 time_t seed;
21 int i;
22
23 time(&seed);
24 _Py_MT_GenRand_Init(&state, seed);
gregory.p.smith 2012/01/15 02:18:38 Include the pid, system uptime and any other easy
25
26 Py_RndHashSeed = _Py_MT_GenRand_Int32(&state);
27 if (Py_RndHashSeed == -1) {
28 Py_RndHashSeed = -2;
29 }
30
31 }
32 }
33
34 /* Randomized hash seed */
35 Py_hash_t
36 Py_GetRndHashSeed(void)
37 {
38 return Py_RndHashSeed;
39 }
OLDNEW

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+