Skip to content

Commit 63187db

Browse files
committed
Rationalise RBC PRNGs
1 parent 06e7df7 commit 63187db

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Code/configuration/SimConfig.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ namespace hemelb::configuration
8989
PhysicalPosition origin_m;
9090
};
9191

92+
// Using std::minstd_rand with a 32 bit unsigned seed/state.
93+
using PrngSeedType = std::uint32_t;
94+
9295
struct CellInserterConfig {
93-
std::int64_t seed;
96+
PrngSeedType seed;
9497
std::string template_name;
9598
quantity_union<double, "s", "lattice"> offset;
9699
Angle theta_rad;

Code/redblood/CellControllerBuilder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ namespace hemelb::redblood {
233233
auto time = std::make_shared<LatticeTime>(timeStep - 1e0
234234
+ std::numeric_limits<LatticeTime>::epsilon() - offset);
235235

236-
std::default_random_engine randomGenerator(conf.seed);
236+
std::minstd_rand randomGenerator(conf.seed);
237237
std::uniform_real_distribution<double> uniformDistribution(-1.0, 1.0);
238238

239239
auto condition = [time, timeStep, dt, uniformDistribution, randomGenerator]() mutable

Code/redblood/RBCInserter.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace hemelb::redblood
3232
*/
3333
class RBCInserter
3434
{
35-
public:
35+
public:
3636
/**
3737
* Creates an RBC Inserter.
3838
*
@@ -106,12 +106,14 @@ namespace hemelb::redblood
106106
//! Red blood cell inserter that adds random rotation and translation to each cell
107107
class RBCInserterWithPerturbation : public RBCInserter
108108
{
109-
public:
109+
public:
110+
using PRNG = std::minstd_rand;
111+
110112
RBCInserterWithPerturbation(std::function<bool()> condition,
111113
std::unique_ptr<CellBase const> cell,
112114
util::Matrix3D const &initialRotation, Angle dtheta, Angle dphi,
113115
LatticePosition const& dx, LatticePosition const& dy,
114-
std::default_random_engine::result_type randomGeneratorSeed = std::default_random_engine::default_seed) :
116+
PRNG::result_type randomGeneratorSeed = PRNG::default_seed) :
115117
RBCInserter(condition, std::move(cell)), initialRotation(initialRotation),
116118
dtheta(dtheta), dphi(dphi), dx(dx), dy(dy), randomGenerator(randomGeneratorSeed), uniformDistribution(-1.0,1.0)
117119
{
@@ -129,7 +131,7 @@ namespace hemelb::redblood
129131
//! Two vectors alongst which to move cell
130132
LatticePosition dx, dy;
131133

132-
std::default_random_engine randomGenerator;
134+
PRNG randomGenerator;
133135
std::uniform_real_distribution<double> uniformDistribution;
134136
};
135137

0 commit comments

Comments
 (0)