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

Unified Diff: Python/hash.c

Issue 13704: Random number generator in Python core
Patch Set: Created 8 years ago
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 side-by-side diff with in-line comments
Download patch
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Python/hash.c Tue Jan 03 21:48:43 2012 +0100
@@ -0,0 +1,39 @@
+#include "Python.h"
+#include "pyrandom.h"
+
+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
+
+void
+_Py_InitRndHashSeed(void)
+{
+ static int initialized = 0;
+ int result;
+ if (initialized) {
+ return;
+ }
+ initialized = 1;
+
+ result = PyOS_URandom((unsigned char*)&Py_RndHashSeed, sizeof(Py_hash_t));
+ /* fall back to Mersenne twister */
+ if (result == -1) {
+ _Py_MT_RandomState state;
+ time_t seed;
+ int i;
+
+ time(&seed);
+ _Py_MT_GenRand_Init(&state, seed);
gregory.p.smith 2012/01/15 02:18:38 Include the pid, system uptime and any other easy
+
+ Py_RndHashSeed = _Py_MT_GenRand_Int32(&state);
+ if (Py_RndHashSeed == -1) {
+ Py_RndHashSeed = -2;
+ }
+
+ }
+}
+
+/* Randomized hash seed */
+Py_hash_t
+Py_GetRndHashSeed(void)
+{
+ return Py_RndHashSeed;
+}

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