Random sampling in Phobos
jerro
a at a.com
Tue Apr 17 23:14:28 PDT 2012
> Hmmm... I see now that randomSample() is defined without ref in
> Phobos as well. Would you care to check whether my suggestion
> fixes your problem? If so, it is a bug in Phobos that should
> be fixed.
>
> -Lars
It is a bug in Phobos but it isn't related to passing by value
(see the thread in D.learn).
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.
More information about the Digitalmars-d
mailing list