On Tuesday, 26 January 2016 at 12:07:59 UTC, Andrei Alexandrescu
wrote:
I think a pseudo-rng as a forward range is useful. It's good in
testing and experimentation to fork a sequence of pseudo-random
numbers, turn the clock back, etc. Essentially I see no harm in
it; it's always easy to make a forward range into an input
range, it's the opposite that's hard. -- Andrei
Yes, but there are other ways to fork that sequence that don't
involve implementing the .save primitive. That's why in my talk
(and here) I distinguish between the .save primitive versus some
other possible primitive -- say, .dup -- whose promise is, "You
can use me to duplicate the state of this range, but you must use
me carefully and in an appropriate context."
This is important, because if you just define pseudo-RNGs as
forward ranges, most people won't read the small print about when
you need to wrap it in an input range (which is pretty much any
time you want to pass it into phobos code and have it behave like
an actual source of randomness). As a result, they'll get
unintended and possibly unnoticed statistical correlations --
annoying for something like a computer game, possibly a serious
consequence if occurring in something like a research simulation.