diff options
author | Bardur Arantsson <bardur@scientician.net> | 2015-12-11 08:09:30 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2015-12-11 08:09:30 +0100 |
commit | 97bcf1bc612d9920390c885b8dcea0b0cda6f246 (patch) | |
tree | f9890fb08cc717fbc8837b58945f32dd64929b45 | |
parent | e4b4f4730a2fb39da766892adbf3419bf5e7f48f (diff) |
Migrate z-rand.c to C++
- Include explicitly instead of via angband.h
- Change to regular functions instead of macros.
63 files changed, 113 insertions, 58 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1fc6a3b4..942946fc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -104,7 +104,7 @@ SET(SRCS_COMMON xtra1.cc xtra2.cc z-form.c - z-rand.c + z-rand.cc z-term.c z-util.c ) diff --git a/src/angband.h b/src/angband.h index ccf5295a..5fbc94e5 100644 --- a/src/angband.h +++ b/src/angband.h @@ -27,7 +27,6 @@ extern "C" { */ #include "z-util.h" #include "z-form.h" -#include "z-rand.h" #include "z-term.h" diff --git a/src/birth.cc b/src/birth.cc index f6120a5a..5d7e64bd 100644 --- a/src/birth.cc +++ b/src/birth.cc @@ -54,6 +54,7 @@ #include "wilderness_map.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <string> diff --git a/src/bldg.cc b/src/bldg.cc index dd433323..7095e8c3 100644 --- a/src/bldg.cc +++ b/src/bldg.cc @@ -40,6 +40,7 @@ #include "variable.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" /* remember building location */ static int building_loc = 0; diff --git a/src/cave.cc b/src/cave.cc index 6a1c513a..5ff31019 100644 --- a/src/cave.cc +++ b/src/cave.cc @@ -19,6 +19,7 @@ #include "util.h" #include "variable.h" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> #include <vector> diff --git a/src/cmd1.cc b/src/cmd1.cc index c11ad4b0..dbb888c7 100644 --- a/src/cmd1.cc +++ b/src/cmd1.cc @@ -45,6 +45,7 @@ #include "wild.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #define MAX_VAMPIRIC_DRAIN 100 diff --git a/src/cmd2.cc b/src/cmd2.cc index fef0dd89..cfdeab44 100644 --- a/src/cmd2.cc +++ b/src/cmd2.cc @@ -48,6 +48,7 @@ #include "wilderness_type_info.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <chrono> #include <thread> diff --git a/src/cmd3.cc b/src/cmd3.cc index 154dd7b1..d1e569ed 100644 --- a/src/cmd3.cc +++ b/src/cmd3.cc @@ -36,6 +36,7 @@ #include "variable.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <cassert> #include <algorithm> diff --git a/src/cmd4.cc b/src/cmd4.cc index b0162a55..b2601744 100644 --- a/src/cmd4.cc +++ b/src/cmd4.cc @@ -35,6 +35,7 @@ #include "variable.h" #include "variable.hpp" #include "xtra1.hpp" +#include "z-rand.hpp" #include <cassert> #include <memory> diff --git a/src/cmd5.cc b/src/cmd5.cc index 2603b9a8..a1dd5cbf 100644 --- a/src/cmd5.cc +++ b/src/cmd5.cc @@ -39,6 +39,7 @@ #include "wizard2.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <boost/noncopyable.hpp> #include <boost/optional.hpp> diff --git a/src/cmd6.cc b/src/cmd6.cc index f27281db..0a5595fa 100644 --- a/src/cmd6.cc +++ b/src/cmd6.cc @@ -47,6 +47,7 @@ #include "wizard2.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <boost/algorithm/string/predicate.hpp> #include <cassert> diff --git a/src/cmd7.cc b/src/cmd7.cc index 6f0412d7..2317f8b9 100644 --- a/src/cmd7.cc +++ b/src/cmd7.cc @@ -37,6 +37,7 @@ #include "variable.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" /* * Describe class powers of Mindcrafters diff --git a/src/corrupt.cc b/src/corrupt.cc index d1a7c530..f182a9e2 100644 --- a/src/corrupt.cc +++ b/src/corrupt.cc @@ -9,6 +9,7 @@ #include "variable.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/dice.cc b/src/dice.cc index 637d2773..187bae68 100644 --- a/src/dice.cc +++ b/src/dice.cc @@ -1,6 +1,6 @@ #include "dice.hpp" -#include "z-rand.h" +#include "z-rand.hpp" #include <cassert> diff --git a/src/dungeon.cc b/src/dungeon.cc index db504f59..c4282a2d 100644 --- a/src/dungeon.cc +++ b/src/dungeon.cc @@ -75,6 +75,7 @@ #include "wizard2.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <boost/filesystem.hpp> #include <cassert> diff --git a/src/files.cc b/src/files.cc index d135c390..30b3e5d0 100644 --- a/src/files.cc +++ b/src/files.cc @@ -52,6 +52,7 @@ #include "wilderness_map.hpp" #include "wilderness_type_info.hpp" #include "xtra1.hpp" +#include "z-rand.hpp" #include <memory> #include <unordered_set> diff --git a/src/gen_evol.cc b/src/gen_evol.cc index f6cee5a7..6f3fbcba 100644 --- a/src/gen_evol.cc +++ b/src/gen_evol.cc @@ -15,6 +15,7 @@ #include "levels.hpp" #include "player_type.hpp" #include "variable.hpp" +#include "z-rand.hpp" /* * Generate a game of life level :) and make it evolve diff --git a/src/gen_maze.cc b/src/gen_maze.cc index 9a3706fa..22722e0a 100644 --- a/src/gen_maze.cc +++ b/src/gen_maze.cc @@ -13,6 +13,7 @@ #include "generate.hpp" #include "levels.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <memory> diff --git a/src/generate.cc b/src/generate.cc index 0f24f7d2..b5733682 100644 --- a/src/generate.cc +++ b/src/generate.cc @@ -35,6 +35,7 @@ #include "vault_type.hpp" #include "wild.hpp" #include "wilderness_map.hpp" +#include "z-rand.hpp" #include <cassert> #include <memory> diff --git a/src/init1.cc b/src/init1.cc index 216b655b..66624ec3 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -44,6 +44,7 @@ #include "vault_type.hpp" #include "wilderness_map.hpp" #include "wilderness_type_info.hpp" +#include "z-rand.hpp" #include <boost/algorithm/string/predicate.hpp> diff --git a/src/joke.cc b/src/joke.cc index fa660243..be272115 100644 --- a/src/joke.cc +++ b/src/joke.cc @@ -4,6 +4,7 @@ #include "options.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" static void gen_joke_place_monster(int r_idx) { diff --git a/src/loadsave.cc b/src/loadsave.cc index c7ebf68d..1fe550fd 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -36,6 +36,7 @@ #include "variable.h" #include "variable.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <cassert> #include <memory> diff --git a/src/melee1.cc b/src/melee1.cc index 9ec5f0c6..bb4c06d1 100644 --- a/src/melee1.cc +++ b/src/melee1.cc @@ -29,6 +29,7 @@ #include "variable.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <boost/algorithm/string/predicate.hpp> diff --git a/src/melee2.cc b/src/melee2.cc index 8478addd..ce2f11a2 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -42,6 +42,7 @@ #include "util.hpp" #include "variable.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/mimic.cc b/src/mimic.cc index b888ec52..edf79f4b 100644 --- a/src/mimic.cc +++ b/src/mimic.cc @@ -5,6 +5,7 @@ #include "stats.hpp" #include "variable.hpp" #include "xtra1.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/monster2.cc b/src/monster2.cc index 0be1cc37..3debb27a 100644 --- a/src/monster2.cc +++ b/src/monster2.cc @@ -38,6 +38,7 @@ #include "wilderness_map.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <algorithm> #include <string> diff --git a/src/monster3.cc b/src/monster3.cc index 915a856d..0d26538c 100644 --- a/src/monster3.cc +++ b/src/monster3.cc @@ -24,6 +24,7 @@ #include "variable.h" #include "variable.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" /* * Is the mon,ster in friendly state(pet, friend, ..) diff --git a/src/object1.cc b/src/object1.cc index c38f2254..6bbf23e9 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -50,6 +50,7 @@ #include "variable.hpp" #include "wilderness_type_info.hpp" #include "xtra1.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/object2.cc b/src/object2.cc index 98d22c2e..620037a3 100644 --- a/src/object2.cc +++ b/src/object2.cc @@ -39,6 +39,7 @@ #include "variable.hpp" #include "wilderness_map.hpp" #include "xtra1.hpp" +#include "z-rand.hpp" #include <algorithm> #include <cassert> diff --git a/src/powers.cc b/src/powers.cc index e1f15d50..a7db2968 100644 --- a/src/powers.cc +++ b/src/powers.cc @@ -37,6 +37,7 @@ #include "variable.h" #include "variable.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" /* * Note: return value indicates the amount of mana to use diff --git a/src/q_dragons.cc b/src/q_dragons.cc index d6f5b1fb..6c6084d1 100644 --- a/src/q_dragons.cc +++ b/src/q_dragons.cc @@ -12,6 +12,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #define cquest (quest[QUEST_DRAGONS]) diff --git a/src/q_eol.cc b/src/q_eol.cc index cfccd156..f27ce9df 100644 --- a/src/q_eol.cc +++ b/src/q_eol.cc @@ -17,6 +17,7 @@ #include "traps.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/q_evil.cc b/src/q_evil.cc index 511644a3..3bc953cd 100644 --- a/src/q_evil.cc +++ b/src/q_evil.cc @@ -12,6 +12,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #define cquest (quest[QUEST_EVIL]) diff --git a/src/q_fireprof.cc b/src/q_fireprof.cc index c561dbc6..021cf2fb 100644 --- a/src/q_fireprof.cc +++ b/src/q_fireprof.cc @@ -14,6 +14,7 @@ #include "traps.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/q_god.cc b/src/q_god.cc index 754802fd..0a3b07e7 100644 --- a/src/q_god.cc +++ b/src/q_god.cc @@ -17,6 +17,7 @@ #include "variable.hpp" #include "wilderness_map.hpp" #include "wilderness_type_info.hpp" +#include "z-rand.hpp" #include <assert.h> diff --git a/src/q_haunted.cc b/src/q_haunted.cc index cbfaa176..57daa40e 100644 --- a/src/q_haunted.cc +++ b/src/q_haunted.cc @@ -13,6 +13,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #define cquest (quest[QUEST_HAUNTED]) diff --git a/src/q_hobbit.cc b/src/q_hobbit.cc index bc3659e9..5a71711e 100644 --- a/src/q_hobbit.cc +++ b/src/q_hobbit.cc @@ -16,6 +16,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/q_library.cc b/src/q_library.cc index 979fbb2f..52a67291 100644 --- a/src/q_library.cc +++ b/src/q_library.cc @@ -15,6 +15,7 @@ #include "util.h" #include "variable.h" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/q_nazgul.cc b/src/q_nazgul.cc index 21bc95c9..15a6a843 100644 --- a/src/q_nazgul.cc +++ b/src/q_nazgul.cc @@ -14,6 +14,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/q_one.cc b/src/q_one.cc index 1aa77610..3741e009 100644 --- a/src/q_one.cc +++ b/src/q_one.cc @@ -22,6 +22,7 @@ #include "town_type.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #define cquest (quest[QUEST_ONE]) diff --git a/src/q_poison.cc b/src/q_poison.cc index d8ecf949..a5b274b0 100644 --- a/src/q_poison.cc +++ b/src/q_poison.cc @@ -17,6 +17,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #define cquest (quest[QUEST_POISON]) diff --git a/src/q_rand.cc b/src/q_rand.cc index 5b265624..4ef79928 100644 --- a/src/q_rand.cc +++ b/src/q_rand.cc @@ -25,6 +25,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/q_shroom.cc b/src/q_shroom.cc index f3a7dd12..89b576d8 100644 --- a/src/q_shroom.cc +++ b/src/q_shroom.cc @@ -16,6 +16,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/q_thief.cc b/src/q_thief.cc index 5019d9d5..0f6543cc 100644 --- a/src/q_thief.cc +++ b/src/q_thief.cc @@ -16,6 +16,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #define cquest (quest[QUEST_THIEVES]) diff --git a/src/q_thrain.cc b/src/q_thrain.cc index 4cdb8566..05def27a 100644 --- a/src/q_thrain.cc +++ b/src/q_thrain.cc @@ -20,6 +20,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/q_troll.cc b/src/q_troll.cc index 7227c1c3..fce3ad49 100644 --- a/src/q_troll.cc +++ b/src/q_troll.cc @@ -15,6 +15,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/q_wight.cc b/src/q_wight.cc index 499535ca..f2cc630c 100644 --- a/src/q_wight.cc +++ b/src/q_wight.cc @@ -14,6 +14,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/q_wolves.cc b/src/q_wolves.cc index 117e8d42..c5863b59 100644 --- a/src/q_wolves.cc +++ b/src/q_wolves.cc @@ -13,6 +13,7 @@ #include "tables.hpp" #include "util.hpp" #include "variable.hpp" +#include "z-rand.hpp" #define cquest (quest[QUEST_WOLVES]) diff --git a/src/randart.cc b/src/randart.cc index 451bf948..5135438a 100644 --- a/src/randart.cc +++ b/src/randart.cc @@ -20,6 +20,7 @@ #include "util.hpp" #include "variable.h" #include "variable.hpp" +#include "z-rand.hpp" #include <memory> #include <vector> diff --git a/src/skills.cc b/src/skills.cc index 997b3bc8..3a14a6ce 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -37,6 +37,7 @@ #include "variable.h" #include "variable.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <algorithm> #include <boost/algorithm/string/predicate.hpp> diff --git a/src/spells1.cc b/src/spells1.cc index 7cb6d2a1..5d6722af 100644 --- a/src/spells1.cc +++ b/src/spells1.cc @@ -43,6 +43,7 @@ #include "wizard2.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <chrono> #include <thread> diff --git a/src/spells2.cc b/src/spells2.cc index b2f294bc..08a643c9 100644 --- a/src/spells2.cc +++ b/src/spells2.cc @@ -40,6 +40,7 @@ #include "variable.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <boost/algorithm/string/predicate.hpp> #include <cassert> diff --git a/src/spells3.cc b/src/spells3.cc index 78dec533..35604f7d 100644 --- a/src/spells3.cc +++ b/src/spells3.cc @@ -27,6 +27,7 @@ #include "util.hpp" #include "variable.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <algorithm> #include <cassert> diff --git a/src/spells4.cc b/src/spells4.cc index b4f924c6..9e708e06 100644 --- a/src/spells4.cc +++ b/src/spells4.cc @@ -14,6 +14,7 @@ #include "util.hpp" #include "util.h" #include "variable.hpp" +#include "z-rand.hpp" #include <algorithm> #include <cassert> diff --git a/src/spells5.cc b/src/spells5.cc index ca6351b6..f503c822 100644 --- a/src/spells5.cc +++ b/src/spells5.cc @@ -5,6 +5,7 @@ #include "spells3.hpp" #include "spells4.hpp" #include "variable.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/store.cc b/src/store.cc index dad3c820..0fbe2e9b 100644 --- a/src/store.cc +++ b/src/store.cc @@ -38,6 +38,7 @@ #include "variable.h" #include "variable.hpp" #include "xtra1.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/traps.cc b/src/traps.cc index d1119513..99428cf9 100644 --- a/src/traps.cc +++ b/src/traps.cc @@ -37,6 +37,7 @@ #include "variable.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" bool_ do_player_trap_call_out(void) { diff --git a/src/wild.cc b/src/wild.cc index e9def091..7724176f 100644 --- a/src/wild.cc +++ b/src/wild.cc @@ -26,6 +26,7 @@ #include "variable.hpp" #include "wilderness_map.hpp" #include "wilderness_type_info.hpp" +#include "z-rand.hpp" #include <memory> diff --git a/src/wizard2.cc b/src/wizard2.cc index 7bce50c7..837d778b 100644 --- a/src/wizard2.cc +++ b/src/wizard2.cc @@ -39,6 +39,7 @@ #include "wizard1.hpp" #include "xtra1.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" /* * Adds a lvl to a monster diff --git a/src/xtra1.cc b/src/xtra1.cc index d213aa39..fd4a11fd 100644 --- a/src/xtra1.cc +++ b/src/xtra1.cc @@ -47,6 +47,7 @@ #include "wilderness_map.hpp" #include "wilderness_type_info.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include <cassert> diff --git a/src/xtra2.cc b/src/xtra2.cc index 87bfe0d7..096f8966 100644 --- a/src/xtra2.cc +++ b/src/xtra2.cc @@ -55,6 +55,7 @@ #include "wilderness_type_info.hpp" #include "wizard2.hpp" #include "xtra1.hpp" +#include "z-rand.hpp" #include <type_traits> #include <cassert> diff --git a/src/z-rand.c b/src/z-rand.cc index ca5b49ae..c06b7893 100644 --- a/src/z-rand.c +++ b/src/z-rand.cc @@ -2,7 +2,7 @@ /* Purpose: a simple random number generator -BEN- */ -#include "z-rand.h" +#include "z-rand.hpp" @@ -154,7 +154,7 @@ s32b Rand_mod(s32b m) * This method has no bias, and is much less affected by patterns * in the "low" bits of the underlying RNG's. */ -s32b Rand_div(s32b m) +static s32b Rand_div(s32b m) { u32b r, n; @@ -351,5 +351,26 @@ s32b maxroll(s16b num, s16b sides) return (num * sides); } +bool magik(int p) { + return rand_int(100) < p; +} + +s32b rand_int(s32b m) +{ + return Rand_div(m); +} +s32b randint(s32b m) +{ + return rand_int(m) + 1; +} +s32b rand_range(s32b a, s32b b) +{ + return a + rand_int(1 + b - a); +} + +s32b rand_spread(s32b a, s32b d) +{ + return a + rand_int(1 + d + d) - d; +} diff --git a/src/z-rand.h b/src/z-rand.hpp index ba17dabe..f2e3ce5c 100644 --- a/src/z-rand.h +++ b/src/z-rand.hpp @@ -1,9 +1,5 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - #include "h-basic.h" @@ -20,71 +16,52 @@ extern "C" { -/**** Available macros ****/ +/**** Available Variables ****/ + + +extern bool_ Rand_quick; +extern u32b Rand_value; +extern u16b Rand_place; +extern u32b Rand_state[RAND_DEG]; + + +/**** Available Functions ****/ + + +void Rand_state_init(u32b seed); +s32b Rand_mod(s32b m); +s16b randnor(int mean, int stand); +s32b damroll(s16b num, s16b sides); +s32b maxroll(s16b num, s16b sides); +/** + * Evaluate to "true" p percent of the time. + */ +bool magik(s32b p); /* * 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) \ - (Rand_div(M)) +s32b rand_int(s32b m); + +/* + * Generate a random long integer X where 1<=X<=M + * Also, "correctly" handle the case of M<=1 + */ +s32b randint(s32b 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)))) +s32b rand_range(s32b a, s32b b); /* * 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)) - - -/* - * Generate a random long integer X where 1<=X<=M - * Also, "correctly" handle the case of M<=1 - */ -#define randint(M) \ - (rand_int(M) + 1) - - -/* - * Evaluate to TRUE "P" percent of the time - */ -#define magik(P) \ - (rand_int(100) < (P)) - - - - -/**** Available Variables ****/ - - -extern bool_ Rand_quick; -extern u32b Rand_value; -extern u16b Rand_place; -extern u32b Rand_state[RAND_DEG]; - - -/**** Available Functions ****/ - - -extern void Rand_state_init(u32b seed); -extern s32b Rand_mod(s32b m); -extern s32b Rand_div(s32b m); -extern s16b randnor(int mean, int stand); -extern s32b damroll(s16b num, s16b sides); -extern s32b maxroll(s16b num, s16b sides); - - -#ifdef __cplusplus -} /* extern "C" */ -#endif +s32b rand_spread(s32b a, s32b d); |