From 11d9d3de5a4244f4810cfa52e172ca5b26df735c Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 30 Jun 2018 16:29:37 +0200 Subject: [PATCH] renamed the global variable r to hrngen; added a commentr about hrngen; fixed hrandom_shuffle in rogueviz-kohonen --- game.cpp | 17 +++++++++++------ rogueviz-kohonen.cpp | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/game.cpp b/game.cpp index da7c13ad..ebdea3d0 100644 --- a/game.cpp +++ b/game.cpp @@ -142,24 +142,29 @@ cellwalker cwt; // single player character position inline cell*& singlepos() { return cwt.c; } inline bool singleused() { return !(shmup::on || multi::players > 1); } -std::mt19937 r; +// the main random number generator for the game +// all the random calls related to the game mechanics (land generation, AI...) should use hrngen +// random calls not related to the game mechanics (graphical effects) should not use hrngen +// this ensures that the game should unfold exactly the same if given the same seed and the same input + +std::mt19937 hrngen; void shrand(int i) { - r.seed(i); + hrngen.seed(i); } -int hrandpos() { return r() & HRANDMAX; } +int hrandpos() { return hrngen() & HRANDMAX; } int hrand(int i) { - return r() % i; + return hrngen() % i; } ld hrandf() { - return (r() & HRANDMAX) / (HRANDMAX + 1.0); + return (hrngen() & HRANDMAX) / (HRANDMAX + 1.0); } int hrandstate() { - std::mt19937 r2 = r; + std::mt19937 r2 = hrngen; return r2() & HRANDMAX; } diff --git a/rogueviz-kohonen.cpp b/rogueviz-kohonen.cpp index dd90f369..8055e18e 100644 --- a/rogueviz-kohonen.cpp +++ b/rogueviz-kohonen.cpp @@ -691,7 +691,7 @@ void describe(cell *c) { help += "\n"; vector> v; for(int s=0; snet, data[s].val), s); - hrandom_shuffle(&v[0], isize(v)); + for(int i=1; i a, pair b) { return a.first < b.first; }); for(int i=0; i