File: roll.c

package info (click to toggle)
xmille 2.0-6
  • links: PTS
  • area: main
  • in suites: potato, slink
  • size: 1,152 kB
  • ctags: 1,731
  • sloc: ansic: 4,347; makefile: 1,462; sh: 2
file content (46 lines) | stat: -rw-r--r-- 720 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 *	This routine rolls ndie nside-sided dice.
 *
 * @(#)roll.c	1.1 (Berkeley) 4/1/82
 *
 */

# define	reg	register

# if (! defined ultrix && ! defined mips && ! defined vax && ! defined linux)
# define	MAXRAND	32767L

roll(ndie, nsides)
int	ndie, nsides; {

	reg long	tot;
	reg unsigned	n;

	tot = 0;
	n = ndie;
#ifndef sun
	while (n--)
		tot += rand();
	return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie;
#else
	while (n--)
		tot += random() % nsides + 1;
	return tot;
#endif
}

# 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