OSDN Git Service

v3.0.0 Alpha5 OSDN最終版
[hengband/hengband.git] / src / z-rand.h
1 /* File: z-rand.h */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison, and others
5  *
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.  Other copyrights may also apply.
9  */
10
11
12 #ifndef INCLUDED_Z_RAND_H
13 #define INCLUDED_Z_RAND_H
14
15 #include "h-basic.h"
16
17
18
19 /**** Available constants ****/
20
21
22 /*
23  * Random Number Generator -- Degree of "complex" RNG -- see "misc.c"
24  * This value is hard-coded at 63 for a wide variety of reasons.
25  */
26 #define RAND_DEG 63
27
28
29
30
31 /**** Available macros ****/
32
33
34 /*
35  * Generates a random long integer X where O<=X<M.
36  * The integer X falls along a uniform distribution.
37  * For example, if M is 100, you get "percentile dice"
38  */
39 #define randint0(M) \
40         ((s32b)Rand_div(M))
41
42 /*
43  * Generates a random long integer X where A<=X<=B
44  * The integer X falls along a uniform distribution.
45  * Note: rand_range(0,N-1) == randint0(N)
46  */
47 #define rand_range(A,B) \
48         ((A) + (randint0(1+(B)-(A))))
49
50 /*
51  * Generate a random long integer X where A-D<=X<=A+D
52  * The integer X falls along a uniform distribution.
53  * Note: rand_spread(A,D) == rand_range(A-D,A+D)
54  */
55 #define rand_spread(A,D) \
56         ((A) + (randint0(1+(D)+(D))) - (D))
57
58
59 /*
60  * Generate a random long integer X where 1<=X<=M
61  * Also, "correctly" handle the case of M<=1
62  */
63 #define randint1(M) \
64         (randint0(M) + 1)
65
66
67 /*
68  * Evaluate to TRUE "P" percent of the time
69  */
70 #define magik(P) \
71         (randint0(100) < (P))
72
73
74 #define one_in_(X) \
75         (randint0(X) == 0)
76
77 /*
78  * Evaluate to TRUE "S" percent of the time
79  */
80 #define saving_throw(S) \
81         (randint0(100) < (S))
82
83
84 /**** Available Variables ****/
85
86 extern u16b Rand_place;
87 extern u32b Rand_state[RAND_DEG];
88
89
90 /**** Available Functions ****/
91
92 extern void Rand_state_init(void);
93 extern void Rand_state_set(u32b seed);
94 extern void Rand_state_backup(u32b* backup_state);
95 extern void Rand_state_restore(u32b* backup_state);
96 extern s32b Rand_div(s32b m);
97 extern s16b randnor(int mean, int stand);
98 extern s16b damroll(int num, DICE_SID sides);
99 extern s16b maxroll(int num, DICE_SID sides);
100 extern s32b div_round(s32b n, s32b d);
101 extern s32b Rand_external(s32b m);
102
103
104 #endif
105
106