X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/0e57b353967966db0b9a4d68736daaa410eafd24..1473e837300a6a867630da6e114a3c6262e28a85:/rogue/random.c diff --git a/rogue/random.c b/rogue/random.c index 6e2abc60..f119c0f9 100644 --- a/rogue/random.c +++ b/rogue/random.c @@ -1,4 +1,4 @@ -/* $NetBSD: random.c,v 1.3 1995/04/22 10:28:06 cgd Exp $ */ +/* $NetBSD: random.c,v 1.8 2009/08/12 08:44:45 dholland Exp $ */ /* * Copyright (c) 1988, 1993 @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -36,14 +32,17 @@ * SUCH DAMAGE. */ +#include #ifndef lint #if 0 static char sccsid[] = "@(#)random.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: random.c,v 1.3 1995/04/22 10:28:06 cgd Exp $"; +__RCSID("$NetBSD: random.c,v 1.8 2009/08/12 08:44:45 dholland Exp $"); #endif #endif /* not lint */ +#include "rogue.h" + /* * random.c * @@ -57,11 +56,11 @@ static char rcsid[] = "$NetBSD: random.c,v 1.3 1995/04/22 10:28:06 cgd Exp $"; */ static long rntb[32] = { - 3, 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, + 3, 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, 0xe369735d, - 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, + 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b, 0x27fb47b9 }; @@ -74,13 +73,14 @@ static int rand_deg = 31; static int rand_sep = 3; static long *end_ptr = &rntb[32]; -srrandom(x) -int x; +static long rrandom(void); + +void +srrandom(int x) { - register int i; - long rrandom(); + int i; - state[0] = (long) x; + state[0] = x; if (rand_type != 0) { for (i = 1; i < rand_deg; i++) { state[i] = 1103515245 * state[i - 1] + 12345; @@ -88,16 +88,16 @@ int x; fptr = &state[rand_sep]; rptr = &state[0]; for (i = 0; i < 10 * rand_deg; i++) { - (void) rrandom(); + (void)rrandom(); } } } -long -rrandom() +static long +rrandom(void) { long i; - + if (rand_type == 0) { i = state[0] = (state[0]*1103515245 + 12345) & 0x7fffffff; } else { @@ -115,10 +115,10 @@ rrandom() return(i); } -get_rand(x, y) -register int x, y; +int +get_rand(int x, int y) { - register int r, t; + int r, t; long lr; if (x > y) { @@ -127,20 +127,20 @@ register int x, y; x = t; } lr = rrandom(); - lr &= (long) 0x00003fff; - r = (int) lr; + lr &= 0x00003fffL; + r = (int)lr; r = (r % ((y - x) + 1)) + x; return(r); } -rand_percent(percentage) -register int percentage; +int +rand_percent(int percentage) { return(get_rand(1, 100) <= percentage); } -coin_toss() +int +coin_toss(void) { - return(((rrandom() & 01) ? 1 : 0)); }