www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17068] New: Range-based seeding of MersenneTwisterEngine is

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

          Issue ID: 17068
           Summary: Range-based seeding of MersenneTwisterEngine is
                    inconsistent with C++11
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: joseph.wakeling webdrake.net

Created attachment 1631
  --> https://issues.dlang.org/attachment.cgi?id=1631&action=edit
Small example of range-based seeding of Phobos Mersenne Twister

std.random's `MersenneTwisterEngine` includes a `seed` method that accepts an
input range from which the state of the generator can be initialized.  This
method superficially seems similar to the sequence-based seeding mechanism that
can be used when seeding the C++11 <random> `mt19937` engine, but its behaviour
is different in several ways:

* the Phobos method will reject any range whose length is less than the size of
the generator's internal state array.  By contrast the C++11 `mt19937` accepts
a seed sequence of any length (including 1);

* seeding with identical sequences produces completely different results for
the C++11 and D versions.  Besides simply being inconsistent (and probably also
at odds with reference seeding methods for the Mersenne Twister) this may make
it harder for users to port C++ code to D.

It is therefore suggested to implement a new range-based seeding mechanism that
matches the C++11 seed-sequence behaviour, and deprecate the old seeding
method.

--
Jan 07 2017