aboutsummaryrefslogtreecommitdiff
path: root/libio/dbz/random.c
blob: 1d8de3a2b44d965ba0c09879f609b2cfde0f5ead (plain)
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
/*
 * random-number generator for testing
 */
static unsigned long next = 1;

/*
 - range - generate a random number within an inclusive range
 *
 * Algorithm from ANSI C standard.  Limitation:  max-min <= 32767.
 */
int
range(min, max)
int min;
int max;
{
	register int temp;

	next = next * 1103515245 + 12345;
	temp = (int)((next/65536)%32768);
	return(temp%(max - min + 1) + min);
}

/*
 - seed - seed random number generator
 */
void
seed(n)
long n;
{
	next = (unsigned long)n;
}