diff options
author | mycroft <mycroft@NetBSD.org> | 1993-04-19 10:19:41 +0000 |
---|---|---|
committer | mycroft <mycroft@NetBSD.org> | 1993-04-19 10:19:41 +0000 |
commit | 225aeae6d8220143cb24ffcbe7c1ca2941643670 (patch) | |
tree | a237857d5a0db0a8da7463e30d5a8a9dbd2d5fa9 /monop/roll.c | |
parent | 9b85680687e77d758ed4d5f002375aa6f88dc803 (diff) | |
download | bsdgames-darwin-225aeae6d8220143cb24ffcbe7c1ca2941643670.tar.gz bsdgames-darwin-225aeae6d8220143cb24ffcbe7c1ca2941643670.tar.zst bsdgames-darwin-225aeae6d8220143cb24ffcbe7c1ca2941643670.zip |
Use POSIX RAND_MAX rather than guessing.
Diffstat (limited to 'monop/roll.c')
-rw-r--r-- | monop/roll.c | 23 |
1 files changed, 3 insertions, 20 deletions
diff --git a/monop/roll.c b/monop/roll.c index 9de116f4..002cf788 100644 --- a/monop/roll.c +++ b/monop/roll.c @@ -39,25 +39,9 @@ static char sccsid[] = "@(#)roll.c 5.5 (Berkeley) 6/1/90"; * This routine rolls ndie nside-sided dice. */ -# define reg register +#include <stdlib.h> -# if !defined(vax) && !defined(tahoe) -# define MAXRAND 32767L - -roll(ndie, nsides) -int ndie, nsides; { - - reg long tot; - reg unsigned n, r; - - tot = 0; - n = ndie; - while (n--) - tot += rand(); - return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie; -} - -# else +#define reg register roll(ndie, nsides) reg int ndie, nsides; { @@ -68,7 +52,6 @@ reg int ndie, nsides; { num_sides = nsides; tot = 0; while (ndie--) - tot += (r = rand()) * (num_sides / 017777777777) + 1; + tot += (r = rand()) * (num_sides / RAND_MAX) + 1; return tot; } -# endif |