samedi 5 mars 2022

Is there a pseudo-random number generator engine in the C++ standard library that supports querying the nth random number for a given seed?

My use case is that I am doing something akin to generative art that involves lazy range-v3 range views containing randomly generated geometric primitives.

I am limited by the fact that for certain operations, when iterating over the aggregate range view, the computation performed by the range views' iteration implementation requires accessing the same random number twice. These numbers are ultimately coming from ranges::views::generate returning numbers generated by std::mt19937. When the generate happens twice it will return different numbers.

One way around this problem would be to do basically the following instead of using views::generate:

ranges::views::iota(0) | 
ranges::views::transform([](int n){return nth_random_number(n, some_rnd_engine);}

my question is is it possible to implement nth_random_number(i, some_rnd_engine) with anything in the C++ standard library. Note that the above is just pseudocode in the actual code I need the separation between engine and distribution, etc., as in standard library.

I've read that a linear congruential engine should be able to do this, and indeed there is one in the standard library, but I doesn't appear to provide a way of querying it in the way I want. Is there some way of implementing my desired behavior?




Aucun commentaire:

Enregistrer un commentaire