Skip to content

Commit

Permalink
Added Random::nextBool().
Browse files Browse the repository at this point in the history
  • Loading branch information
afritz1 committed Dec 15, 2024
1 parent 4207aa7 commit f326295
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion OpenTESArena/src/Entities/EntityChunkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions OpenTESArena/src/Math/Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions OpenTESArena/src/Math/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
2 changes: 1 addition & 1 deletion OpenTESArena/src/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f326295

Please sign in to comment.