SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
randomstream.h File Reference
#include <cmath>
#include <cstdint>
#include <random>
#include <string>
Include dependency graph for randomstream.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  RandomStream
 A seeded, independent stream of random numbers. More...

Functions

std::uint64_t DrawRandomSeed ()
 A seed drawn from the operating system's entropy source.
bool ParseRandomSeed (const std::string &text, std::uint64_t &seed)
 Parses a user-entered seed.
RandomStream & ThreadRandomStream ()

Variables

constexpr std::uint64_t DefaultRandomSeed = 20261016
 The stream for code outside the MCMC that needs random numbers.

Function Documentation

◆ DrawRandomSeed()

std::uint64_t DrawRandomSeed ( )
inline

A seed drawn from the operating system's entropy source.

Used when the user leaves the seed blank. It is 32 bits so that it is easy to read back and type in to repeat a run.

Definition at line 100 of file randomstream.h.

Referenced by CMCMC< T >::initialize(), CMCMC< T >::initialize(), and ParseRandomSeed().

◆ ParseRandomSeed()

bool ParseRandomSeed ( const std::string & text,
std::uint64_t & seed )
inline

Parses a user-entered seed.

Parameters
textDecimal digits, or blank
seedSet to the parsed seed, or to a newly drawn one if text is blank
Returns
false if text is neither blank nor a non-negative integer that fits in 64 bits

Definition at line 112 of file randomstream.h.

References DrawRandomSeed().

Referenced by SourceSinkData::MCMC(), and Conductor::ResolveRandomSeed().

◆ ThreadRandomStream()

RandomStream & ThreadRandomStream ( )
inline

Definition at line 152 of file randomstream.h.

References DefaultRandomSeed.

Referenced by GADistribution::GetRndUniF(), and GetRndUnif().

Variable Documentation

◆ DefaultRandomSeed

std::uint64_t DefaultRandomSeed = 20261016
constexpr

The stream for code outside the MCMC that needs random numbers.

One per thread, so parallel code never shares a generator. Every thread's stream starts from the same fixed seed (DefaultRandomSeed), so a run is repeatable; code whose result must not depend on what ran before it (the Levenberg-Marquardt starting point, Error Analysis) uses its own RandomStream instead. Because every thread's stream starts from the same seed, parallel code must not draw from it: give each chain or task its own RandomStream(seed, index), as the MCMC does.

Definition at line 150 of file randomstream.h.

Referenced by SourceSinkData::SolveLevenberg_Marquardt(), and ThreadRandomStream().