[Issue 7067] std.random.RandomSample and RandomCover are poorly designed

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Feb 28 12:32:46 PST 2015


https://issues.dlang.org/show_bug.cgi?id=7067

Martin Nowak <code at dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code at dawg.eu

--- Comment #19 from Martin Nowak <code at dawg.eu> ---
We had a talk about this during the 2nd D meetup in Berlin.
One remaining question was how to deal with memory management when using a
reference type RNG.

I came up with a different solution and less invasive solution.

We simply disable implicit copying of RNGs (@disable this(this)) and ask people
to use explicitly use .save when copying is indeed intended.

We can even deprecate postblit like so.

    deprecated("Please use .save to explicitly copy RNGs.")
    this(this) {}

Internally we'd need to change all copying to use std.algorithm.move.

If reference semantic is wanted people can use either
    new Random(unpredictableSeed)
or
    refCounted(rnd)
    refCounted(Random(unpredictableSeed))
or (unsafe)
    refRange(&rnd)
.

This should also work for combined random generators like.

new Exponential(Random(unpredictableSeed))

refCounted(Exponential(Random(unpredictableSeed)))

auto rng = Exponential(Random(unpredictableSeed));
refRange(&rng);

--


More information about the Digitalmars-d-bugs mailing list