merge Alex's dual rng proposal with the isaac64 rng code and adjust

This is branched from Alex's hallu-rng-stability branch,
with two build corrections (detect.c, zap.c), and merged
with  the isaac64 branch that we have ready to go.

Alex's dual rng is supported by setting up the array
of multiple isaac64 contexts.

I stuck with Alex's approach of passing the rng function
name around as the parameter (rng or rn2_on_display_rng)
for the new additional parameter needed for
set_random(), init_random(), reseed_random(),
and init_isaac64().
This commit is contained in:
nhmall
2019-01-28 19:43:55 -05:00
parent 819ee796f2
commit 457e4b68aa
7 changed files with 37 additions and 23 deletions
+3 -3
View File
@@ -925,8 +925,8 @@ E char *FDECL(strstri, (const char *, const char *));
#endif #endif
E boolean E boolean
FDECL(fuzzymatch, (const char *, const char *, const char *, BOOLEAN_P)); FDECL(fuzzymatch, (const char *, const char *, const char *, BOOLEAN_P));
E void NDECL(init_random); E void FDECL(init_random, (int FDECL((*fn), (int))));
E void NDECL(reseed_random); E void FDECL(reseed_random, (int FDECL((*fn), (int))));
E time_t NDECL(getnow); E time_t NDECL(getnow);
E int NDECL(getyear); E int NDECL(getyear);
#if 0 #if 0
@@ -2105,7 +2105,7 @@ E void FDECL(genl_outrip, (winid, int, time_t));
/* ### rnd.c ### */ /* ### rnd.c ### */
#ifdef USE_ISAAC64 #ifdef USE_ISAAC64
E void FDECL(init_isaac64, (unsigned long)); E void FDECL(init_isaac64, (unsigned long, int FDECL((*fn), (int))));
E long NDECL(nhrand); E long NDECL(nhrand);
#endif #endif
E int FDECL(rn2, (int)); E int FDECL(rn2, (int));
+2 -2
View File
@@ -869,10 +869,10 @@ int src_cursed;
obj.ox = x; obj.ox = x;
obj.oy = y; obj.oy = y;
} }
obj.otyp = !Hallucination ? GOLD_PIECE : random_object(); obj.otyp = !Hallucination ? GOLD_PIECE : random_object(rn2_on_display_rng);
obj.quan = (long) ((obj.otyp == GOLD_PIECE) ? rnd(10) obj.quan = (long) ((obj.otyp == GOLD_PIECE) ? rnd(10)
: objects[obj.otyp].oc_merge ? rnd(2) : 1); : objects[obj.otyp].oc_merge ? rnd(2) : 1);
obj.corpsenm = random_monster(); /* if otyp == CORPSE */ obj.corpsenm = random_monster(rn2); /* if otyp == CORPSE */
map_object(&obj, 1); map_object(&obj, 1);
} else if (trap) { } else if (trap) {
map_trap(trap, 1); map_trap(trap, 1);
+2 -1
View File
@@ -1420,7 +1420,8 @@ boolean at_stairs, falling, portal;
/* we'll reach here if running in wizard mode */ /* we'll reach here if running in wizard mode */
error("Cannot continue this game."); error("Cannot continue this game.");
} }
reseed_random(); reseed_random(rn2);
reseed_random(rn2_on_display_rng);
minit(); /* ZEROCOMP */ minit(); /* ZEROCOMP */
getlev(fd, hackpid, new_ledger, FALSE); getlev(fd, hackpid, new_ledger, FALSE);
(void) nhclose(fd); (void) nhclose(fd);
+22 -12
View File
@@ -51,8 +51,8 @@
boolean fuzzymatch (const char *, const char *, boolean fuzzymatch (const char *, const char *,
const char *, boolean) const char *, boolean)
void setrandom (void) void setrandom (void)
void init_random (void) void init_random (fn)
void reseed_random (void) void reseed_random (fn)
time_t getnow (void) time_t getnow (void)
int getyear (void) int getyear (void)
char * yymmdd (time_t) char * yymmdd (time_t)
@@ -851,12 +851,20 @@ extern struct tm *FDECL(localtime, (time_t *));
STATIC_DCL struct tm *NDECL(getlt); STATIC_DCL struct tm *NDECL(getlt);
/* Sets the seed for the random number generator */ /* Sets the seed for the random number generator */
static void
set_random(unsigned long seed)
{
#ifdef USE_ISAAC64 #ifdef USE_ISAAC64
init_isaac64(seed); static void
#else set_random(seed, fn)
unsigned long seed;
int FDECL((*fn), (int));
{
init_isaac64(seed, fn);
}
#else /* USE_ISAAC64 */
static void
set_random(seed, fn)
unsigned long seed;
int FDECL((*fn),(int));
{
/* the types are different enough here that sweeping the different /* the types are different enough here that sweeping the different
* routine names into one via #defines is even more confusing * routine names into one via #defines is even more confusing
*/ */
@@ -877,8 +885,8 @@ set_random(unsigned long seed)
# endif # endif
# endif # endif
# endif # endif
#endif
} }
#endif /* USE_ISAAC64 */
/* An appropriate version of this must always be provided in /* An appropriate version of this must always be provided in
port-specific code somewhere. It returns a number suitable port-specific code somewhere. It returns a number suitable
@@ -890,19 +898,21 @@ extern unsigned long NDECL(sys_random_seed);
* Only call once. * Only call once.
*/ */
void void
init_random() init_random(fn)
int FDECL((*fn),(int));
{ {
set_random(sys_random_seed()); set_random(sys_random_seed(), fn);
} }
/* Reshuffles the random number generator. */ /* Reshuffles the random number generator. */
void void
reseed_random() reseed_random(fn)
int FDECL((*fn),(int));
{ {
/* only reseed if we are certain that the seed generation is unguessable /* only reseed if we are certain that the seed generation is unguessable
* by the players. */ * by the players. */
if (has_strong_rngseed) if (has_strong_rngseed)
init_random(); init_random(fn);
} }
time_t time_t
+4 -2
View File
@@ -982,7 +982,8 @@ mklev()
struct mkroom *croom; struct mkroom *croom;
int ridx; int ridx;
reseed_random(); reseed_random(rn2);
reseed_random(rn2_on_display_rng);
init_mapseen(&u.uz); init_mapseen(&u.uz);
if (getbones()) if (getbones())
@@ -1012,7 +1013,8 @@ mklev()
for (ridx = 0; ridx < SIZE(rooms); ridx++) for (ridx = 0; ridx < SIZE(rooms); ridx++)
rooms[ridx].orig_rtype = rooms[ridx].rtype; rooms[ridx].orig_rtype = rooms[ridx].rtype;
reseed_random(); reseed_random(rn2);
reseed_random(rn2_on_display_rng);
} }
void void
+3 -2
View File
@@ -691,8 +691,9 @@ initoptions_init()
/* set up the command parsing */ /* set up the command parsing */
reset_commands(TRUE); /* init */ reset_commands(TRUE); /* init */
/* initialize the random number generator */ /* initialize the random number generator(s) */
init_random(); init_random(rn2);
init_random(rn2_on_display_rng);
/* for detection of configfile options specified multiple times */ /* for detection of configfile options specified multiple times */
iflags.opt_booldup = iflags.opt_compdup = (int *) 0; iflags.opt_booldup = iflags.opt_compdup = (int *) 0;
+1 -1
View File
@@ -1488,7 +1488,7 @@ int id;
/* now change it into something laid by the hero */ /* now change it into something laid by the hero */
while (tryct--) { while (tryct--) {
mnum = can_be_hatched(random_monster()); mnum = can_be_hatched(random_monster(rn2));
if (mnum != NON_PM && !dead_species(mnum, TRUE)) { if (mnum != NON_PM && !dead_species(mnum, TRUE)) {
otmp->spe = 1; /* laid by hero */ otmp->spe = 1; /* laid by hero */
set_corpsenm(otmp, mnum); /* also sets hatch timer */ set_corpsenm(otmp, mnum); /* also sets hatch timer */