need -x file for obscene fortunes
[unix-history] / usr / src / games / monop / roll.c
CommitLineData
dd3d6f67 1/*
d99e6414 2 * Copyright (c) 1980 Regents of the University of California.
e10e1c15
KB
3 * All rights reserved.
4 *
102fca3d 5 * %sccs.include.redist.c%
dd3d6f67
KB
6 */
7
8#ifndef lint
102fca3d 9static char sccsid[] = "@(#)roll.c 5.5 (Berkeley) %G%";
e10e1c15 10#endif /* not lint */
dd3d6f67
KB
11
12/*
13 * This routine rolls ndie nside-sided dice.
14 */
15
16# define reg register
17
574481b9 18# if !defined(vax) && !defined(tahoe)
dd3d6f67
KB
19# define MAXRAND 32767L
20
21roll(ndie, nsides)
22int 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
36roll(ndie, nsides)
37reg 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