date and time created 87/09/26 19:04:45 by bostic
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sun, 27 Sep 1987 10:04:45 +0000 (02:04 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sun, 27 Sep 1987 10:04:45 +0000 (02:04 -0800)
SCCS-vsn: games/monop/roll.c 5.1

usr/src/games/monop/roll.c [new file with mode: 0644]

diff --git a/usr/src/games/monop/roll.c b/usr/src/games/monop/roll.c
new file mode 100644 (file)
index 0000000..719d37e
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)roll.c     5.1 (Berkeley) %G%";
+#endif not lint
+
+/*
+ *     This routine rolls ndie nside-sided dice.
+ */
+
+# define       reg     register
+
+# ifndef vax
+# define       MAXRAND 32767L
+
+roll(ndie, nsides)
+int    ndie, nsides; {
+
+       reg long        tot;
+       reg unsigned    n, r;
+
+       tot = 0;
+       n = ndie;
+       while (n--)
+               tot += rand();
+       return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie;
+}
+
+# else
+
+roll(ndie, nsides)
+reg int        ndie, nsides; {
+
+       reg int         tot, r;
+       reg double      num_sides;
+
+       num_sides = nsides;
+       tot = 0;
+       while (ndie--)
+               tot += (r = rand()) * (num_sides / 017777777777) + 1;
+       return tot;
+}
+# endif