1*32260Sbostic /* 2*32260Sbostic * Copyright (c) 1987 Regents of the University of California. 3*32260Sbostic * All rights reserved. The Berkeley software License Agreement 4*32260Sbostic * specifies the terms and conditions for redistribution. 5*32260Sbostic */ 6*32260Sbostic 7*32260Sbostic #ifndef lint 8*32260Sbostic static char sccsid[] = "@(#)roll.c 5.1 (Berkeley) 09/26/87"; 9*32260Sbostic #endif not lint 10*32260Sbostic 11*32260Sbostic /* 12*32260Sbostic * This routine rolls ndie nside-sided dice. 13*32260Sbostic */ 14*32260Sbostic 15*32260Sbostic # define reg register 16*32260Sbostic 17*32260Sbostic # ifndef vax 18*32260Sbostic # define MAXRAND 32767L 19*32260Sbostic 20*32260Sbostic roll(ndie, nsides) 21*32260Sbostic int ndie, nsides; { 22*32260Sbostic 23*32260Sbostic reg long tot; 24*32260Sbostic reg unsigned n, r; 25*32260Sbostic 26*32260Sbostic tot = 0; 27*32260Sbostic n = ndie; 28*32260Sbostic while (n--) 29*32260Sbostic tot += rand(); 30*32260Sbostic return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie; 31*32260Sbostic } 32*32260Sbostic 33*32260Sbostic # else 34*32260Sbostic 35*32260Sbostic roll(ndie, nsides) 36*32260Sbostic reg int ndie, nsides; { 37*32260Sbostic 38*32260Sbostic reg int tot, r; 39*32260Sbostic reg double num_sides; 40*32260Sbostic 41*32260Sbostic num_sides = nsides; 42*32260Sbostic tot = 0; 43*32260Sbostic while (ndie--) 44*32260Sbostic tot += (r = rand()) * (num_sides / 017777777777) + 1; 45*32260Sbostic return tot; 46*32260Sbostic } 47*32260Sbostic # endif 48