xso::generator — Discard Method

We have an instance method to advance the state while ignoring the generated outputs.

1constexpr void discard(std::uint64_t n);
1
Calls the step method n times without recording any output.
The discard() method is a slow and dumb approach to advancing the state ahead in its orbit. For large values of n, the same thing is achieved much more efficiently by using the jump methods.

Example:

#include <xoshiro.h>
int main()
{
1    xso::rng f;
2    xso::rng g = f;

    std::size_t n = 10;
    std::cout << "Calling f() " << n << " times:\n";
    for (std::size_t i = 0; i < 10; ++i)
        std::cout << "Call " << i << ": f() = " << f() << '\n';

    std::cout << "Making sure the jumped forward copy of f matches:\n";
3    g.discard(n);
4    std::cout << "f() = " << f() << '\n';
    std::cout << "g() = " << g() << '\n';
}
1
Create a randomly seeded RNG.
2
Make a copy of that generator — one with the exact same state.
3
We have called f() multiple times and now get g to the same point by using the discard method.
4
One more call to f() and g() to demonstrate they have reached the identical point in their random number streams.

Output: Varies from run to run

Calling f() 10 times:
Call 0: f() = 14005126867685016518
Call 1: f() = 10640180379987258470
Call 2: f() = 16367042443805637715
Call 3: f() = 10852054829793099863
Call 4: f() = 17355665557991136519
Call 5: f() = 17884768122497745551
Call 6: f() = 8981322931967380562
Call 7: f() = 9724290714337168340
Call 8: f() = 11553202802824749703
Call 9: f() = 5222239817378406001
Making sure the jumped forward copy of f matches:
f() = 14624851349943862646
g() = 14624851349943862646

See Also

jump

Back to top