Pseudo-random numbers in [0, n), covering all numbers in n steps?
Joseph Rushton Wakeling via Digitalmars-d
digitalmars-d at puremagic.com
Fri Feb 26 15:45:26 PST 2016
On Friday, 26 February 2016 at 23:05:00 UTC, John Colvin wrote:
> This was what I was trying to get at in my initial post, but I
> failed to get the idea across properly.
Yea. It didn't even click with me at first, because when I first
read Andrei's email I jumped straight in my head to the thought,
"OK, so what _is_ an appropriate algorithm for lazily calculating
a random permutation using O(1) storage space?"
The good news is that, AFAICS, that is a readily solvable
problem. It's inevitably more computationally complex than an
in-place random shuffle -- O(n log n) instead of O(n) -- but
algorithms do exist that could be adapted for Phobos.
More information about the Digitalmars-d
mailing list