Bug 10899 – std.random.Random default RNG type should be customizable at compile-time

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-26T04:36:00Z
Last change time
2017-07-03T00:06:16Z
Assigned to
nobody
Creator
joseph.wakeling

Comments

Comment #0 by joseph.wakeling — 2013-08-26T04:36:30Z
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.
Comment #1 by dlang-bugzilla — 2017-07-03T00:06:16Z
Hmm, I don't think this is going to be implemented, because... - Historically the BDFLs have been opposed by compiler switches which change program behaviour. - Changing the RNG globally may break existing code which used Random with a fixed seed. - As you've mentioned, (In reply to Joseph Rushton Wakeling from comment #0) > 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. Random is an alias, so any symbols which have Random in their signature will have different mangling (and fully-resolved type) depending on the compile-time Random version selected. - This bug is close to 4 years old with no replies, so I doubt someone is going to start working on this now.