* grid, so that repeating the same marking will give
* the same answer instead of a different one.
*/
- random_state *rs = random_init((char *)guesses->grid,
- (state->w+2)*(state->h+2) *
- sizeof(unsigned int));
+ random_state *rs = random_new((char *)guesses->grid,
+ (state->w+2)*(state->h+2) *
+ sizeof(unsigned int));
n = random_upto(rs, n);
random_free(rs);
for (i = 0; i < guesses->nlasers; i++) {
* grid, so that repeating the same marking will give
* the same answer instead of a different one.
*/
- random_state *rs = random_init((char *)guesses->grid,
- (state->w+2)*(state->h+2) *
- sizeof(unsigned int));
+ random_state *rs = random_new((char *)guesses->grid,
+ (state->w+2)*(state->h+2) *
+ sizeof(unsigned int));
n = random_upto(rs, n);
random_free(rs);
for (i = 0; i < guesses->nlasers; i++) {
If a back end needs random numbers at some point during normal play,
it can create a fresh \c{random_state} by first calling
\c{get_random_seed} (\k{frontend-get-random-seed}) and then passing
-the returned seed data to \cw{random_init()}.
+the returned seed data to \cw{random_new()}.
This is likely not to be what you want. If a puzzle needs randomness
in the middle of play, it's likely to be more sensible to store some
\c{random_state}. One of these is managed by each mid-end, for
example, and passed to the back end to generate a game with.
-\S{utils-random-init} \cw{random_init()}
+\S{utils-random-init} \cw{random_new()}
-\c random_state *random_init(char *seed, int len);
+\c random_state *random_new(char *seed, int len);
Allocates, initialises and returns a new \c{random_state}. The input
data is used as the seed for the random number stream (i.e. using
* outlines by the judicious use of diagonally divided squares.
*/
{
- random_state *rs = random_init(desc, strlen(desc));
+ random_state *rs = random_new(desc, strlen(desc));
int *squares = snewn(wh, int);
int done_something;
me->frontend = fe;
me->ourgame = ourgame;
- me->random = random_init(randseed, randseedsize);
+ me->random = random_new(randseed, randseedsize);
me->nstates = me->statesize = me->statepos = 0;
me->states = NULL;
me->params = ourgame->default_params();
sfree(me->aux_info);
me->aux_info = NULL;
- rs = random_init(me->seedstr, strlen(me->seedstr));
+ rs = random_new(me->seedstr, strlen(me->seedstr));
/*
* If this midend has been instantiated without providing a
* drawing API, it is non-interactive. This means that it's
ui->cur_y = ui->cy = state->height / 2;
ui->cur_visible = FALSE;
get_random_seed(&seed, &seedsize);
- ui->rs = random_init(seed, seedsize);
+ ui->rs = random_new(seed, seedsize);
sfree(seed);
return ui;
/*
* random.c
*/
-random_state *random_init(char *seed, int len);
+random_state *random_new(char *seed, int len);
random_state *random_copy(random_state *tocopy);
unsigned long random_bits(random_state *state, int bits);
unsigned long random_upto(random_state *state, unsigned long limit);
int pos;
};
-random_state *random_init(char *seed, int len)
+random_state *random_new(char *seed, int len)
{
random_state *state;