xref: /csrg-svn/games/monop/roll.c (revision 32261)
132260Sbostic /*
232260Sbostic  * Copyright (c) 1987 Regents of the University of California.
332260Sbostic  * All rights reserved.  The Berkeley software License Agreement
432260Sbostic  * specifies the terms and conditions for redistribution.
532260Sbostic  */
632260Sbostic 
732260Sbostic #ifndef lint
8*32261Sbostic static char sccsid[] = "@(#)roll.c	5.2 (Berkeley) 09/26/87";
932260Sbostic #endif not lint
1032260Sbostic 
1132260Sbostic /*
1232260Sbostic  *	This routine rolls ndie nside-sided dice.
1332260Sbostic  */
1432260Sbostic 
1532260Sbostic # define	reg	register
1632260Sbostic 
17*32261Sbostic # if !defined(vax) && !defined(tahoe)
1832260Sbostic # define	MAXRAND	32767L
1932260Sbostic 
2032260Sbostic roll(ndie, nsides)
2132260Sbostic int	ndie, nsides; {
2232260Sbostic 
2332260Sbostic 	reg long	tot;
2432260Sbostic 	reg unsigned	n, r;
2532260Sbostic 
2632260Sbostic 	tot = 0;
2732260Sbostic 	n = ndie;
2832260Sbostic 	while (n--)
2932260Sbostic 		tot += rand();
3032260Sbostic 	return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie;
3132260Sbostic }
3232260Sbostic 
3332260Sbostic # else
3432260Sbostic 
3532260Sbostic roll(ndie, nsides)
3632260Sbostic reg int	ndie, nsides; {
3732260Sbostic 
3832260Sbostic 	reg int		tot, r;
3932260Sbostic 	reg double	num_sides;
4032260Sbostic 
4132260Sbostic 	num_sides = nsides;
4232260Sbostic 	tot = 0;
4332260Sbostic 	while (ndie--)
4432260Sbostic 		tot += (r = rand()) * (num_sides / 017777777777) + 1;
4532260Sbostic 	return tot;
4632260Sbostic }
4732260Sbostic # endif
48