www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10899] New: std.random.Random default RNG type should be customizable at compile-time

http://d.puremagic.com/issues/show_bug.cgi?id=10899

           Summary: std.random.Random default RNG type should be
                    customizable at compile-time
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: joseph.wakeling webdrake.net


--- Comment #0 from Joseph Rushton Wakeling <joseph.wakeling webdrake.net>
2013-08-26 04:36:30 PDT ---
Phobos' std.random currently defines an alias Random to the default RNG type. 
This is intended to be implementation-dependent, inasmuch as the optimal choice
of default may be different hardware setups; so while currently we just have

    alias Mt19937 Random;

one could in principle have instead,

    version(/* low-powered architectures */)
    {
        alias Random = Xorshift;
    }
    else
    {
        alias Random = Mt19937;
    }

(just as an example).

However, it's also useful for the user to be able to directly customize the
definition of Random at compile-time.  Something like:

    dmd -version Random=MinstdRand0 myfile.d

There are two main motivations for this:

    * std.random's current value-type implementation makes
      various functions dangerous to use except with the
      default thread-global RNG rndGen, which is of type
      Random.  Unless one can customize the definition of
      Random, one is restricted to Mt19937, which is
      imperfect for many use cases (it's larger and slower
      than e.g. Xorshift or MinstdRand).

    * Even with the RNG type problems solved, it's convenient
      to be able to code without worrying about defining an
      RNG, just relying on the fact that random functions will
      make use of rndGen if nothing else is specified.  But
      one may nevertheless wish to vary the RNG _type_ for
      various reasons (speed, memory usage, ...).

Caveats: Could a build-local customization of Random have implications for
linking?  I guess redefining the alias itself is not a problem but there could
also be problems with clashes in the namespace for rndGen.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 26 2013