OSDN Git Service

Merge remote-tracking branch 'remotes/hengbandosx/english-_ptr-in-message' into featu...
[hengband/hengband.git] / src / term / 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 #ifndef INCLUDED_Z_RAND_H
12 #define INCLUDED_Z_RAND_H
13
14 #include "system/h-basic.h"
15
16 /**** Available constants ****/
17
18 /*
19  * Random Number Generator -- Degree of "complex" RNG -- see "misc.c"
20  * This value is hard-coded at 63 for a wide variety of reasons.
21  */
22 #define RAND_DEG 63
23
24 /**** Available macros ****/
25
26 /*
27  * Generates a random long integer X where O<=X<M.
28  * The integer X falls along a uniform distribution.
29  * For example, if M is 100, you get "percentile dice"
30  */
31 #define randint0(M) ((s32b)Rand_div(M))
32
33 /*
34  * Generates a random long integer X where A<=X<=B
35  * The integer X falls along a uniform distribution.
36  * Note: rand_range(0,N-1) == randint0(N)
37  */
38 #define rand_range(A, B) ((A) + (randint0(1 + (B) - (A))))
39
40 /*
41  * Generate a random long integer X where A-D<=X<=A+D
42  * The integer X falls along a uniform distribution.
43  * Note: rand_spread(A,D) == rand_range(A-D,A+D)
44  */
45 #define rand_spread(A, D) ((A) + (randint0(1 + (D) + (D))) - (D))
46
47 /*
48  * Generate a random long integer X where 1<=X<=M
49  * Also, "correctly" handle the case of M<=1
50  */
51 #define randint1(M) (randint0(M) + 1)
52
53 /*
54  * Evaluate to TRUE "P" percent of the time
55  */
56 #define magik(P) (randint0(100) < (P))
57
58 #define one_in_(X) (randint0(X) == 0)
59
60 /*
61  * Evaluate to TRUE "S" percent of the time
62  */
63 #define saving_throw(S) (randint0(100) < (S))
64
65 extern u16b Rand_place;
66 extern u32b Rand_state[RAND_DEG];
67
68 void Rand_state_init(void);
69 void Rand_state_set(u32b seed);
70 void Rand_state_backup(u32b *backup_state);
71 void Rand_state_restore(u32b *backup_state);
72 s32b Rand_div(s32b m);
73 s16b randnor(int mean, int stand);
74 s16b damroll(DICE_NUMBER num, DICE_SID sides);
75 s16b maxroll(DICE_NUMBER num, DICE_SID sides);
76 s32b div_round(s32b n, s32b d);
77 s32b Rand_external(s32b m);
78 bool next_bool();
79
80 #endif