On Saturday, 26 November 2016 at 06:46:19 UTC, Martin Nowak wrote:
Yes the problems are inadvertent copies and a disabled
this(this) would prevent that. RNGs should have unique
ownership of their internal state.
Using InputRanges with phobos is somewhat clumsy. Maybe people
have been burned by those and now generally consider
InputRanges as broken.
Maybe non-copyability needs to become a requirement for
InputRanges.
I remember you made that suggestion of disabled this(this) to me
a while back, and I did use it for this small collection of RNGs:
https://github.com/WebDrake/dxorshift
We should add a reference RNG that transforms any other RNG
into an input range that shares the actual RNG.
We already have refRange for that, no?
Also refCounted(Random(unpredictableSeed)) should work.
RefRange still has the issue that it only forwards the range
primitives and not other properties such as the `isUniformRandom`
enum. But those are probably fixable.
However, these approaches basically cover the case of something
where an instance is initialized high up in the program and
passed around by ref throughout its lifetime. That doesn't
address the question of how random _algorithms_ like
`RandomSample` could be updated for safety (since they might
often need to be initialized multiple times in the inner loops of
a program). See:
https://forum.dlang.org/post/gnlvyogolkmocujtn...@forum.dlang.org
https://forum.dlang.org/post/gpsilefdillwtleuw...@forum.dlang.org
for some discussion of the problem.