Random sampling in Phobos

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Tue Apr 17 23:49:19 PDT 2012


On 18/04/12 08:14, jerro wrote:
> I agree that copying random generators is error prone but
> randomSampler taking the generator by ref wouldn't be enough
> to fix that problem. The generator gets saved in a member in
> a RandomSampler struct, so that member would have to be a
> pointer to avoid copying (so RandomSampler would have to be
> instantiated with Random* instead of Random). I usually avoid
> this kind of problems by using pointers to random generators
> instead of random generators everywhere.

I suppose a pointer is one solution, but that has an issue all of its own -- 
what if the pointed-to RNG is deleted?  Copying the RNG by value is at least 
safe in this sense.



More information about the Digitalmars-d mailing list