Cleanup: rename random_init() to random_new(), because it actually

_allocates_ a random_state rather than just initialising one passed
in by the caller.

[originally from svn r6412]
This commit is contained in:
Simon Tatham
2005-10-22 16:27:54 +00:00
parent 4faecc7726
commit 23ab000b7b
7 changed files with 15 additions and 15 deletions

View File

@ -692,9 +692,9 @@ static int check_guesses(game_state *state, int cagey)
* 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++) {
@ -727,9 +727,9 @@ static int check_guesses(game_state *state, int cagey)
* 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++) {

View File

@ -1478,7 +1478,7 @@ otherwise be obvious.
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
@ -3044,9 +3044,9 @@ generator has an \e{explicit} state object called a
\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

2
map.c
View File

@ -1868,7 +1868,7 @@ static game_state *new_game(midend *me, game_params *params, char *desc)
* 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;

View File

@ -102,7 +102,7 @@ midend *midend_new(frontend *fe, const game *ourgame,
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();
@ -342,7 +342,7 @@ void midend_new_game(midend *me)
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

2
net.c
View File

@ -1804,7 +1804,7 @@ static game_ui *new_ui(game_state *state)
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;

View File

@ -287,7 +287,7 @@ extern char ver[];
/*
* 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);

View File

@ -207,7 +207,7 @@ struct random_state {
int pos;
};
random_state *random_init(char *seed, int len)
random_state *random_new(char *seed, int len)
{
random_state *state;