RandomSample with specified random number generator

Dmitry Olshansky dmitry.olsh at gmail.com
Thu Jun 14 14:41:34 PDT 2012


On 15.06.2012 1:37, jerro wrote:
>> Assuming API changes are permissible (a big IF), I think the way to do
>> it might be something like
>>
>> auto randomSample(R, UniformRNG = Random, seed)(R r, size_t n, seed s
>> = unpredictableSeed)
>>
>> ... meaning that the user has an option to specify an RNG _type_
>> without specifying a seed, and that the seed can be either
>> unpredictable or specific.
>>
>> The user could also not specify a RNG type, in which case the default
>> RNG type would be used, but would be seeded unpredictably.
>
> Issues with copying rngs are not unique to randomSample - anyone
> who uses random number generators will run into them
> sooner or later. So the problem is not that randomSample takes
> a rng as a parameter - it's that rngs are value types. The
> proper solution would be to make them reference types.

Good insight.

> I don't
> know if that can be done now as it would surely break some code,
> but people can use pointers to rngs instead of rngs themselves.
> I think not doing that will cause bugs irregardless of how
> randomSample works. I know it would cause bugs in my code.
>



-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list