4 * Copyright (c) 1997 Ben Harrison, and others
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.
12 #ifndef INCLUDED_Z_RAND_H
13 #define INCLUDED_Z_RAND_H
19 /**** Available constants ****/
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.
31 /**** Available macros ****/
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"
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)
47 #define rand_range(A,B) \
48 ((A) + (randint0(1+(B)-(A))))
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)
55 #define rand_spread(A,D) \
56 ((A) + (randint0(1+(D)+(D))) - (D))
60 * Generate a random long integer X where 1<=X<=M
61 * Also, "correctly" handle the case of M<=1
68 * Evaluate to TRUE "P" percent of the time
78 * Evaluate to TRUE "S" percent of the time
80 #define saving_throw(S) \
84 /**** Available Variables ****/
86 extern u16b Rand_place;
87 extern u32b Rand_state[RAND_DEG];
90 /**** Available Functions ****/
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);