Mir Random [WIP]
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Thu Nov 24 01:42:40 PST 2016
On 23.11.2016 00:55, Andrei Alexandrescu wrote:
> On 11/22/16 1:31 AM, Ilya Yaroshenko wrote:
>> - `opCall` API instead of range interface is used (similar to C++)
>
> This seems like a gratuitous departure from common D practice. Random
> number generators are most naturally modeled in D as infinite ranges. --
> Andrei
I would posit that it is not actually natural to model random numbers as
ranges. Not every random object is a sequence. Different samples are
(ideally) independent, so there is little conceptual motivation to group
them together -- it just increases the logistic overhead needed to get
at the single samples. I.e., the most natural way to use a PRNG range is
as follows:
PRNG range;
auto sample(){
auto r=range.front;
range.popFront();
return r;
}
PRNGs are an example where global state is actually desirable, because
in contrast to most other programming tasks, usually less predictability
is good.
More information about the Digitalmars-d
mailing list