A New Algorithm for Controlled Randomness
&gt; Together we came up with a solution that solves this with O(n) memory usage where n is the number of choices, and O(log n) CPU cost. And it allows you to decide if you want to be more random or more deterministic.<p>I think you can do the same thing and solve all the same problems in O(1) time per sample using the alias method plus shuffling while blending between regular uniform samples and jittered uniform samples.<p>- Build your alias map of M buckets, the distribution you want to sample<p>- Take a set of N uniform samples, and use a knob to blend between regular and jittered. It looks like:
    r=lerp(knob, 0.5, rand())&#x2F;N<p>- Shuffle the uniform samples, e.g. std::random_shuffle(). This can be done incrementally, per sample (<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fisher–Yates_shuffle" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fisher–Yates_shuffle</a>).<p>- Plug the uniform sample into the alias map to find your sampled choice.<p>- Repeat when you run out of the N uniform samples.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Alias_method" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Alias_method</a><p><a href="http:&#x2F;&#x2F;www.keithschwarz.com&#x2F;darts-dice-coins&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.keithschwarz.com&#x2F;darts-dice-coins&#x2F;</a>