Skip to content

Commit

Permalink
Fix setting random seed to current time (#2651)
Browse files Browse the repository at this point in the history
Setting the random seed to 0 or lower of a `Random` generator will now set it to the UNIX timestamp of the current time.
  • Loading branch information
Vankata453 authored Oct 5, 2023
1 parent 6ed22a0 commit 6bbfb45
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/math/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "math/random.hpp"

#include <ctime>
#include <limits>

Random graphicsRandom;
Expand All @@ -29,6 +30,9 @@ Random::Random() :
void
Random::seed(int v)
{
if (v <= 0)
v = static_cast<int>(std::time(nullptr)); // Use the UNIX timestamp of the current time as a seed.

m_generator.seed(v);
}

Expand Down

0 comments on commit 6bbfb45

Please sign in to comment.