diff options
| author | Martin Hořeňovský | 2019-10-06 21:47:54 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2019-10-07 19:56:23 +0200 |
| commit | 535da5c5132bcbba6f29c60ed6bb7ded29b9ec3e (patch) | |
| tree | 2cf1263bd8d3707e1f4087885dbdf7fa5a7ed84c /include/internal/catch_run_context.cpp | |
| parent | 319cb9e1daec5076ff1a3acd10b959c2bce05c5b (diff) | |
| download | catch3-535da5c5132bcbba6f29c60ed6bb7ded29b9ec3e.tar.gz | |
Introduce Catch's own RNG based on the PCG family of RNGs
In the future, we will also want to introduce our own
`uniform_int_distribution` and `uniform_real_distribution` to get
repeatable test runs across different platforms.
Diffstat (limited to 'include/internal/catch_run_context.cpp')
| -rw-r--r-- | include/internal/catch_run_context.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/include/internal/catch_run_context.cpp b/include/internal/catch_run_context.cpp index 79f906d6..2eb84fb9 100644 --- a/include/internal/catch_run_context.cpp +++ b/include/internal/catch_run_context.cpp @@ -506,4 +506,16 @@ namespace Catch { else CATCH_INTERNAL_ERROR("No result capture instance"); } + + void seedRng(IConfig const& config) { + if (config.rngSeed() != 0) { + std::srand(config.rngSeed()); + rng().seed(config.rngSeed()); + } + } + + unsigned int rngSeed() { + return getCurrentContext().getConfig()->rngSeed(); + } + } |