msvcrt: Reimplement rand() and srand() to use per-thread data for the
random seed.
diff --git a/dlls/msvcrt/misc.c b/dlls/msvcrt/misc.c
index 83f798d..6455e39 100644
--- a/dlls/msvcrt/misc.c
+++ b/dlls/msvcrt/misc.c
@@ -39,11 +39,25 @@
}
/*********************************************************************
+ * srand (MSVCRT.@)
+ */
+void MSVCRT_srand( unsigned int seed )
+{
+ thread_data_t *data = msvcrt_get_thread_data();
+ data->random_seed = seed;
+}
+
+/*********************************************************************
* rand (MSVCRT.@)
*/
int MSVCRT_rand(void)
{
- return (rand() & 0x7fff);
+ thread_data_t *data = msvcrt_get_thread_data();
+
+ /* this is the algorithm used by MSVC, according to
+ * http://en.wikipedia.org/wiki/List_of_pseudorandom_number_generators */
+ data->random_seed = data->random_seed * 214013 + 2531011;
+ return (data->random_seed >> 16) & MSVCRT_RAND_MAX;
}
/*********************************************************************