X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/c380832d0b832bcfbd16e760ade393f9adab02b6..HEAD:/random.c diff --git a/random.c b/random.c index 08bc608..6d278a4 100644 --- a/random.c +++ b/random.c @@ -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; @@ -221,6 +221,16 @@ random_state *random_init(char *seed, int len) return state; } +random_state *random_copy(random_state *tocopy) +{ + random_state *result; + result = snew(random_state); + memcpy(result->seedbuf, tocopy->seedbuf, sizeof(result->seedbuf)); + memcpy(result->databuf, tocopy->databuf, sizeof(result->databuf)); + result->pos = tocopy->pos; + return result; +} + unsigned long random_bits(random_state *state, int bits) { unsigned long ret = 0; @@ -264,7 +274,7 @@ unsigned long random_upto(random_state *state, unsigned long limit) bits += 3; assert(bits < 32); - max = 1 << bits; + max = 1L << bits; divisor = max / limit; max = limit * divisor;