xref: /original-bsd/games/monop/roll.c (revision 89af8021)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)roll.c	5.6 (Berkeley) 09/29/92";
10 #endif /* not lint */
11 
12 /*
13  *	This routine rolls ndie nside-sided dice.
14  */
15 
16 # define	reg	register
17 
18 # if defined(pdp11)
19 # define	MAXRAND	32767L
20 
21 roll(ndie, nsides)
22 int	ndie, nsides; {
23 
24 	reg long	tot;
25 	reg unsigned	n, r;
26 
27 	tot = 0;
28 	n = ndie;
29 	while (n--)
30 		tot += rand();
31 	return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie;
32 }
33 
34 # else
35 
36 roll(ndie, nsides)
37 reg int	ndie, nsides; {
38 
39 	reg int		tot, r;
40 	reg double	num_sides;
41 
42 	num_sides = nsides;
43 	tot = 0;
44 	while (ndie--)
45 		tot += (r = rand()) * (num_sides / 017777777777) + 1;
46 	return tot;
47 }
48 # endif
49