Encapsulate direct use of random(), srandom() in chance.c

Wrap roll0() around random(), and seed_prng() around srandom().  In
preparation of replacing the PRNG.
This commit is contained in:
Markus Armbruster 2012-08-14 19:23:12 +02:00
parent 8eb78a5a80
commit 866859e912
17 changed files with 87 additions and 49 deletions

View file

@ -50,6 +50,7 @@
#include "sys/socket.h"
#endif
#include "chance.h"
#include "empio.h"
#include "empthread.h"
#include "file.h"
@ -349,7 +350,7 @@ crash_dump(void)
static void
init_server(unsigned seed, int force_bad_state)
{
srandom(seed);
seed_prng(seed);
#if defined(_WIN32)
loc_NTInit();
#endif

View file

@ -30,7 +30,7 @@
* Dave Pare, 1994
* Steve McClure, 1996
* Ron Koenderink, 2005
* Markus Armbruster, 2007-2010
* Markus Armbruster, 2007-2012
*/
#include <config.h>
@ -40,6 +40,7 @@
#include <sys/wait.h>
#endif
#include <time.h>
#include "chance.h"
#include "empthread.h"
#include "file.h"
#include "game.h"
@ -129,7 +130,7 @@ update_sched(void *unused)
next_update = update_time[0];
if (next_update) {
if (update_window > 0)
next_update += random() % update_window;
next_update += roll0(update_window);
logerror("Next update at %s", ctime(&next_update));
/* sleep until update is scheduled to go off */
empth_sleep(next_update);