|
SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
|
A seeded, independent stream of random numbers. More...
#include <randomstream.h>

Public Member Functions | |
| RandomStream (std::uint64_t seed=0, std::uint64_t stream=0) | |
Stream number stream derived from seed. | |
| void | Reseed (std::uint64_t seed, std::uint64_t stream=0) |
| double | Uniform () |
| Uniform on [0, 1), with 53 random bits. | |
| double | UniformPositive () |
| Uniform on (0, 1], never zero, for taking logarithms. | |
| double | StandardNormal () |
| Standard normal, by the Box-Muller transform. | |
| double | Normal (double mean, double stdev) |
Normal with mean mean and standard deviation stdev. | |
| std::uint64_t | Index (std::uint64_t n) |
| Uniform integer on [0, n), n > 0. | |
Private Attributes | |
| std::mt19937_64 | engine_ |
| double | spare_normal_ = 0.0 |
| bool | has_spare_normal_ = false |
A seeded, independent stream of random numbers.
Every random number in SedSAT3 comes from a RandomStream. The engine is std::mt19937_64 seeded through std::seed_seq; both are fully specified by the C++ standard, and the uniform and normal values are computed here from the engine's raw output rather than with std::uniform_real_distribution and std::normal_distribution, whose algorithms differ between standard libraries. The same seed therefore gives the same numbers with GCC, Clang and MSVC, on Linux, macOS and Windows.
A stream is not thread-safe. Code that runs in parallel gives each chain or thread its own stream, seeded from a master seed and the stream's index, so results do not depend on how work is scheduled across threads.
Definition at line 26 of file randomstream.h.
|
inlineexplicit |
Stream number stream derived from seed.
Different stream numbers with the same seed give statistically independent sequences.
Definition at line 35 of file randomstream.h.
References Reseed().
|
inline |
Uniform integer on [0, n), n > 0.
Definition at line 83 of file randomstream.h.
References Uniform().
|
inline |
Normal with mean mean and standard deviation stdev.
Definition at line 77 of file randomstream.h.
References StandardNormal().
|
inline |
Definition at line 40 of file randomstream.h.
References engine_, and has_spare_normal_.
Referenced by RandomStream().
|
inline |
Standard normal, by the Box-Muller transform.
Definition at line 62 of file randomstream.h.
References has_spare_normal_, spare_normal_, Uniform(), and UniformPositive().
Referenced by SourceSinkData::InitializeContributionsRandomlySoftmax(), Normal(), CMCMC< T >::perturb(), and CMCMC< SourceSinkData >::UpdateProposalCovariance().
|
inline |
Uniform on [0, 1), with 53 random bits.
Definition at line 50 of file randomstream.h.
References engine_.
Referenced by GADistribution::GetRndUniF(), GetRndUnif(), Index(), SourceSinkData::InitializeContributionsRandomly(), SourceSinkData::RandomlypickSamples(), and StandardNormal().
|
inline |
Uniform on (0, 1], never zero, for taking logarithms.
Definition at line 56 of file randomstream.h.
References engine_.
Referenced by StandardNormal().
|
private |
Definition at line 89 of file randomstream.h.
Referenced by Reseed(), Uniform(), and UniformPositive().
|
private |
Definition at line 91 of file randomstream.h.
Referenced by Reseed(), and StandardNormal().
|
private |
Definition at line 90 of file randomstream.h.
Referenced by StandardNormal().