Pseudo-random numbers in [0, n), covering all numbers in n steps?
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Thu Feb 25 10:19:56 PST 2016
On Thursday, 25 February 2016 at 17:27:25 UTC, Andrei
Alexandrescu wrote:
> So we have
> https://dlang.org/phobos/std_random.html#.randomCover which
> needs to awkwardly allocate memory to keep track of the
> portions of the array already covered.
>
> This could be fixed by devising a PRNG that takes a given
> period n and generates all numbers in [0, n) in exactly n steps.
>
> However, I've had difficulty finding such PRNGs. Most want the
> maximum period possible so they're not concerned with a given
> period. Any insights?
I don't think that's a good idea. A prng is closed path through a
state space and it doesn't matter where you start on said path,
you're going to follow the same closed path through the state
space.
I don't know of an algorithm for generating random permutations
that isn't in-place (or O(N) storage), but I'm not an expert on
the topic so maybe one does exist.
More information about the Digitalmars-d
mailing list