#ifdef G_OS_WIN32
#include <stdlib.h>
+#include <process.h> /* For getpid() */
#endif
/**
*
* The g_rand*_range functions will return high quality equally
* distributed random numbers, whereas for example the
- * `(g_random_int()\%max)` approach often
+ * `(g_random_int()%max)` approach often
* doesn't yield equally distributed numbers.
*
* GLib changed the seeding algorithm for the pseudo-random number
seed[3] = getppid ();
}
#else /* G_OS_WIN32 */
+ /* rand_s() is only available since Visual Studio 2005 */
+#if defined(_MSC_VER) && _MSC_VER >= 1400
gint i;
for (i = 0; i < G_N_ELEMENTS (seed); i++)
rand_s (&seed[i]);
+#else
+#warning Using insecure seed for random number generation because of missing rand_s() in Windows XP
+ GTimeVal now;
+
+ g_get_current_time (&now);
+ seed[0] = now.tv_sec;
+ seed[1] = now.tv_usec;
+ seed[2] = getpid ();
+ seed[3] = 0;
+#endif
+
#endif
return g_rand_new_with_seed_array (seed, 4);