From f3262956b19ffb6d64cac5e122f4a204545553b2 Mon Sep 17 00:00:00 2001 From: Aaron Date: Sun, 15 Dec 2024 06:35:33 -0800 Subject: [PATCH] Added Random::nextBool(). --- OpenTESArena/src/Entities/EntityChunkManager.cpp | 2 +- OpenTESArena/src/Math/Random.cpp | 5 +++++ OpenTESArena/src/Math/Random.h | 3 +++ OpenTESArena/src/Player/Player.cpp | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/OpenTESArena/src/Entities/EntityChunkManager.cpp b/OpenTESArena/src/Entities/EntityChunkManager.cpp index 1d8e23c01..4f3957592 100644 --- a/OpenTESArena/src/Entities/EntityChunkManager.cpp +++ b/OpenTESArena/src/Entities/EntityChunkManager.cpp @@ -325,7 +325,7 @@ void EntityChunkManager::populateChunkEntities(EntityChunk &entityChunk, const V return false; } - const bool isMale = random.next(2) == 0; + const bool isMale = random.nextBool(); const EntityDefID entityDefID = isMale ? citizenGenInfo->maleEntityDefID : citizenGenInfo->femaleEntityDefID; const EntityDefinition &entityDef = isMale ? *citizenGenInfo->maleEntityDef : *citizenGenInfo->femaleEntityDef; const EntityAnimationDefinition &entityAnimDef = entityDef.getAnimDef(); diff --git a/OpenTESArena/src/Math/Random.cpp b/OpenTESArena/src/Math/Random.cpp index 1e332f56c..028d14166 100755 --- a/OpenTESArena/src/Math/Random.cpp +++ b/OpenTESArena/src/Math/Random.cpp @@ -38,6 +38,11 @@ int Random::next(int exclusiveMax) return this->next() % exclusiveMax; } +bool Random::nextBool() +{ + return (this->next() % 2) == 0; +} + double Random::nextReal() { return this->realDistribution(this->generator); diff --git a/OpenTESArena/src/Math/Random.h b/OpenTESArena/src/Math/Random.h index d080a150f..f39f9ea30 100755 --- a/OpenTESArena/src/Math/Random.h +++ b/OpenTESArena/src/Math/Random.h @@ -30,6 +30,9 @@ class Random // Includes 0 to (exclusiveMax - 1). int next(int exclusiveMax); + // Randomly returns true or false. + bool nextBool(); + // Includes [0.0, 1.0). double nextReal(); }; diff --git a/OpenTESArena/src/Player/Player.cpp b/OpenTESArena/src/Player/Player.cpp index f4733f685..e6aa8aa0a 100644 --- a/OpenTESArena/src/Player/Player.cpp +++ b/OpenTESArena/src/Player/Player.cpp @@ -181,7 +181,7 @@ void Player::initRandom(const CharacterClassLibrary &charClassLibrary, const Exe { this->displayName = "Player"; this->firstName = GetFirstName(this->displayName); - this->male = random.next(2) == 0; + this->male = random.nextBool(); this->raceID = random.next(8); this->charClassDefID = random.next(charClassLibrary.getDefinitionCount()); this->portraitID = random.next(10);