xref: /csrg-svn/games/monop/roll.c (revision 34788)
132260Sbostic /*
2*34788Sbostic  * Copyright (c) 1980 Regents of the University of California.
333202Sbostic  * All rights reserved.
433202Sbostic  *
533202Sbostic  * Redistribution and use in source and binary forms are permitted
6*34788Sbostic  * provided that the above copyright notice and this paragraph are
7*34788Sbostic  * duplicated in all such forms and that any documentation,
8*34788Sbostic  * advertising materials, and other materials related to such
9*34788Sbostic  * distribution and use acknowledge that the software was developed
10*34788Sbostic  * by the University of California, Berkeley.  The name of the
11*34788Sbostic  * University may not be used to endorse or promote products derived
12*34788Sbostic  * from this software without specific prior written permission.
13*34788Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*34788Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*34788Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1632260Sbostic  */
1732260Sbostic 
1832260Sbostic #ifndef lint
19*34788Sbostic static char sccsid[] = "@(#)roll.c	5.4 (Berkeley) 06/18/88";
2033202Sbostic #endif /* not lint */
2132260Sbostic 
2232260Sbostic /*
2332260Sbostic  *	This routine rolls ndie nside-sided dice.
2432260Sbostic  */
2532260Sbostic 
2632260Sbostic # define	reg	register
2732260Sbostic 
2832261Sbostic # if !defined(vax) && !defined(tahoe)
2932260Sbostic # define	MAXRAND	32767L
3032260Sbostic 
3132260Sbostic roll(ndie, nsides)
3232260Sbostic int	ndie, nsides; {
3332260Sbostic 
3432260Sbostic 	reg long	tot;
3532260Sbostic 	reg unsigned	n, r;
3632260Sbostic 
3732260Sbostic 	tot = 0;
3832260Sbostic 	n = ndie;
3932260Sbostic 	while (n--)
4032260Sbostic 		tot += rand();
4132260Sbostic 	return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie;
4232260Sbostic }
4332260Sbostic 
4432260Sbostic # else
4532260Sbostic 
4632260Sbostic roll(ndie, nsides)
4732260Sbostic reg int	ndie, nsides; {
4832260Sbostic 
4932260Sbostic 	reg int		tot, r;
5032260Sbostic 	reg double	num_sides;
5132260Sbostic 
5232260Sbostic 	num_sides = nsides;
5332260Sbostic 	tot = 0;
5432260Sbostic 	while (ndie--)
5532260Sbostic 		tot += (r = rand()) * (num_sides / 017777777777) + 1;
5632260Sbostic 	return tot;
5732260Sbostic }
5832260Sbostic # endif
59