xref: /csrg-svn/games/monop/roll.c (revision 60815)
132260Sbostic /*
2*60815Sbostic  * Copyright (c) 1980, 1993
3*60815Sbostic  *	The Regents of the University of California.  All rights reserved.
433202Sbostic  *
542583Sbostic  * %sccs.include.redist.c%
632260Sbostic  */
732260Sbostic 
832260Sbostic #ifndef lint
9*60815Sbostic static char sccsid[] = "@(#)roll.c	8.1 (Berkeley) 05/31/93";
1033202Sbostic #endif /* not lint */
1132260Sbostic 
1232260Sbostic /*
1332260Sbostic  *	This routine rolls ndie nside-sided dice.
1432260Sbostic  */
1532260Sbostic 
1632260Sbostic # define	reg	register
1732260Sbostic 
1856349Sbostic # if defined(pdp11)
1932260Sbostic # define	MAXRAND	32767L
2032260Sbostic 
roll(ndie,nsides)2132260Sbostic roll(ndie, nsides)
2232260Sbostic int	ndie, nsides; {
2332260Sbostic 
2432260Sbostic 	reg long	tot;
2532260Sbostic 	reg unsigned	n, r;
2632260Sbostic 
2732260Sbostic 	tot = 0;
2832260Sbostic 	n = ndie;
2932260Sbostic 	while (n--)
3032260Sbostic 		tot += rand();
3132260Sbostic 	return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie;
3232260Sbostic }
3332260Sbostic 
3432260Sbostic # else
3532260Sbostic 
roll(ndie,nsides)3632260Sbostic roll(ndie, nsides)
3732260Sbostic reg int	ndie, nsides; {
3832260Sbostic 
3932260Sbostic 	reg int		tot, r;
4032260Sbostic 	reg double	num_sides;
4132260Sbostic 
4232260Sbostic 	num_sides = nsides;
4332260Sbostic 	tot = 0;
4432260Sbostic 	while (ndie--)
4532260Sbostic 		tot += (r = rand()) * (num_sides / 017777777777) + 1;
4632260Sbostic 	return tot;
4732260Sbostic }
4832260Sbostic # endif
49