diff options
author | Paul Janzen <pjanzen@cvs.openbsd.org> | 1998-09-20 23:36:57 +0000 |
---|---|---|
committer | Paul Janzen <pjanzen@cvs.openbsd.org> | 1998-09-20 23:36:57 +0000 |
commit | 258e8f6c8fefb0e8f3e410890a5003a86c897a41 (patch) | |
tree | 8f4987a0191afe0747e1b90d6c6c072684ebd9d2 /games/monop/roll.c | |
parent | 9103334d21fd70396d762c44151c3eeee652b1e6 (diff) |
rand -> random; handle EOF; don't overflow on user input; check for calloc()
success; OpenBSD tags; some reformatting and ridding of unused variables.
Diffstat (limited to 'games/monop/roll.c')
-rw-r--r-- | games/monop/roll.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/games/monop/roll.c b/games/monop/roll.c index ddf38a2e790..476f1ed18aa 100644 --- a/games/monop/roll.c +++ b/games/monop/roll.c @@ -1,3 +1,4 @@ +/* $OpenBSD: roll.c,v 1.2 1998/09/20 23:36:56 pjanzen Exp $ */ /* $NetBSD: roll.c,v 1.5 1995/03/23 08:35:13 cgd Exp $ */ /* @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)roll.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: roll.c,v 1.5 1995/03/23 08:35:13 cgd Exp $"; +static char rcsid[] = "$OpenBSD: roll.c,v 1.2 1998/09/20 23:36:56 pjanzen Exp $"; #endif #endif /* not lint */ @@ -47,36 +48,36 @@ static char rcsid[] = "$NetBSD: roll.c,v 1.5 1995/03/23 08:35:13 cgd Exp $"; * This routine rolls ndie nside-sided dice. */ -# define reg register - -# if defined(pdp11) -# define MAXRAND 32767L +#if defined(pdp11) +#define MAXRAND 32767L +int roll(ndie, nsides) -int ndie, nsides; { - - reg long tot; - reg unsigned n, r; + int ndie, nsides; +{ + long tot; + unsigned n, r; tot = 0; n = ndie; while (n--) - tot += rand(); + tot += random(); return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie; } -# else +#else +int roll(ndie, nsides) -reg int ndie, nsides; { - - reg int tot, r; - reg double num_sides; + int ndie, nsides; +{ + int tot, r; + double num_sides; num_sides = nsides; tot = 0; while (ndie--) - tot += (r = rand()) * (num_sides / RAND_MAX) + 1; + tot += (r = random()) * (num_sides / RAND_MAX) + 1; return tot; } -# endif +#endif |