From a0f9f2ff0e3f1f029e5b285971cb7dc4cbec1e3b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1=D1?=
 =?UTF-8?q?=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <lrn1986@gmail.com>
Date: Wed, 23 Nov 2011 21:26:41 +0400
Subject: [PATCH 4/4] Use better random generator on W32

---
 src/util/crypto_random.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 719acf0..9fc1486 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -34,6 +34,35 @@
 
 #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
 
+/* TODO: ndurner, move this to plibc? */
+/* The code is derived from glibc, obviously */
+#if MINGW
+#ifdef RANDOM
+#  undef RANDOM
+#endif
+#ifdef SRANDOM
+#  undef SRANDOM
+#endif
+#define RANDOM() glibc_weak_rand32()
+#define SRANDOM(s) glibc_weak_srand32(s)
+static int32_t glibc_weak_rand32_state = 1;
+
+void
+glibc_weak_srand32 (int32_t s)
+{
+  glibc_weak_rand32_state = s;
+}
+
+int32_t
+glibc_weak_rand32 ()
+{
+  int32_t val = glibc_weak_rand32_state;
+  val = ((glibc_weak_rand32_state * 1103515245) + 12345) & 0x7fffffff;
+  glibc_weak_rand32_state = val;
+  return val;
+}
+#endif
+
 /**
  * Create a cryptographically weak pseudo-random number in the interval of 0 to 1.
  *
-- 
1.7.4

