Skip to content

Repeating values for pcg64_k32_fast #102

@BJTor

Description

@BJTor

After quite a bit of testing I've found that the "fast" versions of the extended pcg generators give enough of a performance boost to be worthwhile. However I am finding that I see repeated value sequences well below the stated period of the generator. I suspect this is my ignorance and I'm setting something up wrong, but for pcg64_k32_fast, advancing the state by 2^126 seems to get us back to an identical state and corresponding identical samples. Example code is below and produces the following output:

% ./pcg64ext_test
Expected period = 2^2174
Advance RNG2 by 8.50706e+37 (2^126) steps.
Sample from RNG1 = 16965488128385771295
Sample from RNG2 = 16965488128385771295

Am I missing something here?


pcg64ext_test.cpp:

#include "pcg_random.hpp"

typedef pcg64_k32_fast RngType; // 2174-bit state, 64-bit samples

int main() {
    // Create two copies of the same generator
    std::cout << "Expected period = 2^" << RngType::period_pow2() << std::endl;
    RngType rng1;
    RngType rng2 = rng1;

    // Tell the second generator to advance by 2^126 steps. This should be well
    // within the expected period (2^2174) so should not repeat.
    RngType::state_type numSteps(1);
    numSteps = numSteps << 126;
    std::cout << "Advance RNG2 by " << double(numSteps) << " (2^126) steps." << std::endl;
    rng2.advance(numSteps);

    std::cout << "Sample from RNG1 = " << rng1() << std::endl;
    std::cout << "Sample from RNG2 = " << rng2() << std::endl;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions