-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathz-rand.h
60 lines (40 loc) · 1.22 KB
/
z-rand.h
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
47
48
49
50
51
52
53
54
55
56
57
58
/* File: z-rand.h */
/*
* Copyright (c) 1997 Ben Harrison, and others
*
* This software may be copied and distributed for educational, research,
* and not for profit purposes provided that this copyright and statement
* are included in all such copies. Other copyrights may also apply.
*/
#ifndef INCLUDED_Z_RAND_H
#define INCLUDED_Z_RAND_H
#include "h-type.h"
/**** Available constants ****/
/*
* The "degree" of the "complex" Random Number Generator.
* This value is hard-coded at 63 for a wide variety of reasons.
*/
#define RAND_DEG 63
/**** Available macros ****/
/*
* Generates a random long integer X where O<=X<M.
* The integer X falls along a uniform distribution.
* For example, if M is 100, you get "percentile dice"
*/
#define rand_int(M) \
((s32b)(rand()%(M)))
/*
* Generates a random long integer X where A<=X<=B
* The integer X falls along a uniform distribution.
* Note: rand_range(0,N-1) == rand_int(N)
*/
#define rand_range(A,B) \
((A) + (rand_int(1+(B)-(A))))
/*
* Generate a random long integer X where A-D<=X<=A+D
* The integer X falls along a uniform distribution.
* Note: rand_spread(A,D) == rand_range(A-D,A+D)
*/
#define rand_spread(A,D) \
((A) + (rand_int(1+(D)+(D))) - (D))
#endif