Replace boost::mt19937 with std::mt19937

Available since C++11 and already used in the codebase.

Ref: #8210
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser
2025-07-17 19:59:56 +02:00
parent a2f15bae4e
commit 6f2f8c13bf
6 changed files with 15 additions and 24 deletions
+1 -3
View File
@@ -29,8 +29,6 @@
#include "lib/timer.h"
#include "maths/MathUtil.h"
#include <boost/random/uniform_int_distribution.hpp>
namespace
{
/**
@@ -594,7 +592,7 @@ std::set<CStr> CObjectBase::CalculateRandomRemainingSelections(rng_t& rng, const
// Choose a random number in the interval [0..totalFreq) to choose one of the variants.
// If the diversity is "none", force 0 to return the first valid variant.
int randNum = diversity == CObjectManager::VariantDiversity::NONE ? 0 : boost::random::uniform_int_distribution<int>(0, totalFreq-1)(rng);
int randNum = diversity == CObjectManager::VariantDiversity::NONE ? 0 : std::uniform_int_distribution<int>(0, totalFreq - 1)(rng);
for (size_t i = 0; i < grp->size(); ++i)
{
randNum -= (allZero ? 1 : (*grp)[i].m_Frequency);
+2 -2
View File
@@ -28,9 +28,9 @@ class CObjectManager;
class CXeromyces;
class XMBElement;
#include <boost/random/mersenne_twister.hpp>
#include <map>
#include <memory>
#include <random>
#include <set>
#include <unordered_set>
#include <vector>
@@ -185,7 +185,7 @@ private:
// A low-quality RNG like rand48 causes visible non-random patterns (particularly
// in large grids of the same actor with consecutive seeds, e.g. forests),
// so use a better one that appears to avoid those patterns
using rng_t = boost::mt19937;
using rng_t = std::mt19937;
std::set<CStr> CalculateRandomRemainingSelections(rng_t& rng, const std::vector<std::set<CStr>>& initialSelections) const;
/**
+1 -3
View File
@@ -40,12 +40,10 @@
#include "renderer/backend/Sampler.h"
#include <algorithm>
#include <boost/random/uniform_real_distribution.hpp>
#include <cmath>
#include <cstddef>
#include <map>
/**
* Interface for particle state variables, which get evaluated for each newly
* constructed particle.
@@ -133,7 +131,7 @@ public:
virtual float Compute(CParticleEmitterType& type, CParticleEmitter&)
{
return boost::random::uniform_real_distribution<float>(m_Min, m_Max)(type.m_Manager.m_RNG);
return std::uniform_real_distribution<float>(m_Min, m_Max)(type.m_Manager.m_RNG);
}
virtual float Min(CParticleEmitterType&)
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -21,8 +21,8 @@
#include "graphics/ParticleEmitter.h"
#include "graphics/ParticleEmitterType.h"
#include <boost/random/mersenne_twister.hpp>
#include <list>
#include <random>
#include <unordered_map>
class SceneCollector;
@@ -55,7 +55,7 @@ public:
Status ReloadChangedFile(const VfsPath& path);
/// Random number generator shared between all particle emitters.
boost::mt19937 m_RNG;
std::mt19937 m_RNG;
private:
float m_CurrentTime;
+4 -7
View File
@@ -20,11 +20,9 @@
#include "lib/types.h"
#include "maths/Sqrt.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/random/variate_generator.hpp>
#include <cmath>
#include <cstddef>
#include <random>
class TestSqrt : public CxxTest::TestSuite
{
@@ -78,13 +76,12 @@ public:
// Test with some random u64s, to make sure the output agrees with floor(sqrt(double))
// (TODO: This might be making non-portable assumptions about sqrt(double))
boost::mt19937 rng;
boost::random::uniform_int_distribution<u64> ints(0, (u64)-1);
boost::variate_generator<boost::mt19937&, boost::random::uniform_int_distribution<u64>> gen(rng, ints);
std::mt19937 rng;
std::uniform_int_distribution<u64> ints(0, (u64)-1);
for (size_t i = 0; i < 1024; ++i)
{
u64 n = gen();
u64 n = ints(rng);
s(n, static_cast<u64>(sqrt(static_cast<double>(n))));
}
}
@@ -22,9 +22,7 @@
#include "simulation2/components/ICmpPosition.h"
#include "simulation2/components/ICmpVision.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_real_distribution.hpp>
#include <random>
#include <optional>
class MockVisionRgm : public ICmpVision
@@ -175,11 +173,11 @@ public:
{ CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(348), entity_pos_t::FromInt(83), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }
cmp->Verify();
boost::mt19937 rng;
std::mt19937 rng;
for (size_t i = 0; i < 1024; ++i)
{
double x = boost::random::uniform_real_distribution<double>(0.0, 512.0)(rng);
double z = boost::random::uniform_real_distribution<double>(0.0, 512.0)(rng);
double x = std::uniform_real_distribution<double>(0.0, 512.0)(rng);
double z = std::uniform_real_distribution<double>(0.0, 512.0)(rng);
{ CMessagePositionChanged msg(100, true, entity_pos_t::FromDouble(x), entity_pos_t::FromDouble(z), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }
cmp->Verify();
}