1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2026-07-05 09:52:43 +00:00

renamed the global variable r to hrngen; added a commentr about hrngen; fixed hrandom_shuffle in rogueviz-kohonen

This commit is contained in:
Zeno Rogue
2018-06-30 16:29:37 +02:00
parent e9c82a5005
commit 11d9d3de5a
2 changed files with 12 additions and 7 deletions
+11 -6
View File
@@ -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;
}