What is the use case of RandomCover?

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Tue Feb 19 04:18:38 PST 2013


On 02/19/2013 12:46 PM, Ivan Kazmenko wrote:
> I'd like to note that my post is about randomCover, not randomSample.  I do see
> the difference between the purpose of randomSample and randomShuffle.  But
> randomCover's effect is, at the first glance, just a slower version of
> randomSample wrapped as a lazy generator.

To be honest, I think RandomCover is (statistically) unsafe to use right now, as 
it takes a copy of the random number generator it is given _by value_.  So 
unless you pass it an unpredictably-seeded new RNG that will not be used in any 
other context, you're going to get correlation between the output of RandomCover 
and other sequences of random numbers you generate elsewhere in your code. 
(This problem is also found in RandomSample, but at least in that case there is 
an alternative of calling rndGen.)

As for purpose -- I think the point of RandomCover is to provide a means of 
generating a random shuffle that doesn't re-order elements of the original range 
in place, and that doesn't require creating a copy.

It's probably worth investigating the algorithms out there for this kind of 
functionality, because I doubt the algorithm that's given is optimal.


More information about the Digitalmars-d-learn mailing list