diff --git a/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.C b/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.C index afba64df74..e2fec45161 100644 --- a/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.C +++ b/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.C @@ -66,18 +66,19 @@ Foam::cachedRandom::cachedRandom(const label seed, const label count) seed_ = seed; } + // Initialise samples + osRandomSeed(seed_); + // Samples will be cached if count > 0 if (count > 0) { samples_.setSize(count); - sampleI_ = 0; - } + forAll(samples_, i) + { + samples_[i] = osRandomDouble(); + } - // Initialise samples - osRandomSeed(seed_); - forAll(samples_, i) - { - samples_[i] = osRandomDouble(); + sampleI_ = 0; } } @@ -90,23 +91,28 @@ Foam::cachedRandom::cachedRandom(const cachedRandom& cr, const bool reset) hasGaussSample_(cr.hasGaussSample_), gaussSample_(cr.gaussSample_) { + //if (sampleI_ == -1) + //{ + // WarningInFunction + // << "Copy constructor called, but samples not being cached. " + // << "This may lead to non-repeatable behaviour" << endl; + // + //} + if (reset) { hasGaussSample_ = false; gaussSample_ = 0; - } - if (sampleI_ == -1) - { - WarningInFunction - << "Copy constructor called, but samples not being cached. " - << "This may lead to non-repeatable behaviour" << endl; - osRandomSeed(seed_); - } - - if (reset && samples_.size()) - { - sampleI_ = 0; + if (samples_.size()) + { + sampleI_ = 0; + } + else + { + // Re-initialise the samples + osRandomSeed(seed_); + } } } diff --git a/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.H b/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.H index 539d8103b1..a42034284a 100644 --- a/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.H +++ b/src/OpenFOAM/primitives/random/cachedRandom/cachedRandom.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -143,6 +143,10 @@ public: template void randomise01(Type& value); + //- Shuffle the values in the list + template + void shuffle(UList& values); + // Global random numbers - consistent across all processors @@ -224,7 +228,7 @@ label cachedRandom::globalPosition