shithub: puzzles

Download patch

ref: 23ab000b7b038b6810e48a71a94b8287c20a6047
parent: 4faecc77264b6d3e84ae24707af5593490f36796
author: Simon Tatham <anakin@pobox.com>
date: Sat Oct 22 12:27:54 EDT 2005

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]

--- a/blackbox.c
+++ b/blackbox.c
@@ -692,9 +692,9 @@
 	     * 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 @@
 	     * 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++) {
--- a/devel.but
+++ b/devel.but
@@ -1478,7 +1478,7 @@
 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 @@
 \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
--- a/map.c
+++ b/map.c
@@ -1868,7 +1868,7 @@
      * 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;
 
--- a/midend.c
+++ b/midend.c
@@ -102,7 +102,7 @@
 
     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 @@
         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
--- a/net.c
+++ b/net.c
@@ -1804,7 +1804,7 @@
     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;
--- a/puzzles.h
+++ b/puzzles.h
@@ -287,7 +287,7 @@
 /*
  * 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);
--- a/random.c
+++ b/random.c
@@ -207,7 +207,7 @@
     int pos;
 };
 
-random_state *random_init(char *seed, int len)
+random_state *random_new(char *seed, int len)
 {
     random_state *state;