On Thursday, 24 November 2016 at 13:45:40 UTC, Jonathan M Davis
wrote:
Alternatively, you could just do rndGen().take(1).front, and as
long as rndGen() gives you a reference type, it works just
fine. Unfortunately, std.random did not use reference types for
its ranges. _That_ is the big mistake of std.random and the
main item that needs to be fixed. There are some other
subtleties (e.g. it's useful to be able to save the state of a
random number generating range, but you don't necessarily
really want it to be a forward range), but those are minor in
comparison to the mistake of std.random using value types
rather than reference types for ranges.
- Jonathan M Davis
The fix is opCall syntax. Reference types are classes, which
would not work without linking DRuntime and Phobos (BetterC).
Refcounting is to slow to implement for users.
Note, that Engines is only backend RNGs. There are also
nonuniform distributions (WIP). See the example of users code:
https://forum.dlang.org/post/nyvtoejvmsaolzaqy...@forum.dlang.org
.
It is very difficult to implement both user random variable and
Engine using Range API. Note, that code should work without
DRuntime and should be simple (the example is user code).
Ilya