mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
The Windows RNG turns out to only give about 16 bits at a time. This
is (a) pretty feeble, and (b) means that although Net seeds transfer between platforms and still generate the same game, there's a suspicious discrepancy in the typical seed _generated_ by each platform. I have a better RNG kicking around in this code base already, so I'll just use it. Each midend has its own random_state, which it passes to new_game_seed() as required. A handy consequence of this is that initial seed data is now passed to midend_new(), which means that new platform implementors are unlikely to forget to seed the RNG because failure to do so causes a compile error! [originally from svn r4187]
This commit is contained in:
11
midend.c
11
midend.c
@ -13,6 +13,8 @@
|
||||
|
||||
struct midend_data {
|
||||
frontend *frontend;
|
||||
random_state *random;
|
||||
|
||||
char *seed;
|
||||
int fresh_seed;
|
||||
int nstates, statesize, statepos;
|
||||
@ -36,11 +38,12 @@ struct midend_data {
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
midend_data *midend_new(frontend *frontend)
|
||||
midend_data *midend_new(frontend *fe, void *randseed, int randseedsize)
|
||||
{
|
||||
midend_data *me = snew(midend_data);
|
||||
|
||||
me->frontend = frontend;
|
||||
me->frontend = fe;
|
||||
me->random = random_init(randseed, randseedsize);
|
||||
me->nstates = me->statesize = me->statepos = 0;
|
||||
me->states = NULL;
|
||||
me->params = default_params();
|
||||
@ -88,7 +91,7 @@ void midend_new_game(midend_data *me)
|
||||
|
||||
if (!me->fresh_seed) {
|
||||
sfree(me->seed);
|
||||
me->seed = new_game_seed(me->params);
|
||||
me->seed = new_game_seed(me->params, me->random);
|
||||
} else
|
||||
me->fresh_seed = FALSE;
|
||||
|
||||
@ -252,7 +255,7 @@ float *midend_colours(midend_data *me, int *ncolours)
|
||||
float *ret;
|
||||
|
||||
if (me->nstates == 0) {
|
||||
char *seed = new_game_seed(me->params);
|
||||
char *seed = new_game_seed(me->params, me->random);
|
||||
state = new_game(me->params, seed);
|
||||
sfree(seed);
|
||||
} else
|
||||
|
Reference in New Issue
Block a user