Mir Random [WIP]

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Wed Nov 23 13:29:03 PST 2016


On Wednesday, November 23, 2016 08:54:30 Andrei Alexandrescu via 
Digitalmars-d wrote:
> On 11/23/2016 06:14 AM, Ilya Yaroshenko wrote:
> > I think that Range API is bad and useless overengineering for RNGs.
>
> So it either "takes 1 minute" to change the interface from opCall to
> ranges (i.e. they're virtually the same thing), or it's the above.
> There's precious little overengineering that can be done in 1 minute
>
> :o). I see you did that in a dozen lines in RandomRangeAdaptor.
>
> I understand you believe the range interface is unnecessary or overkill
> for random number generators. I may even agree for certain cases.
> However, there are a few arguments you may want to consider:
>
> * By virtue of working with D, everybody know what a range is.
> Presenting the RNGs that way instantly evokes a host of knowledge,
> understanding, and idioms.
>
> * D users (or at least a fraction) and several algorithms understand the
> notion of an infinite range and make salient decisions based on that. A
> range interface automatically taps into that.

I've frequently found that in cases where I'm not operating on a range of
values, I really just want a way to get a random number, and having to call
both popFront and front to get it is a bit annoying (it's actually one of
the few places that I've ever used the comma operator). That being said, I
think that the correct solution to that is to add a function to std.random
that takes a range, calls popFront on it, and then returns front so that it
can work with any of the random number generators and avoids problems with
whether or not popFront was called prior to calling front. I have to agree
that creating a different API that uses opCall or whatever instead of a
the range API is a bad idea, particularly when a simple helper function
would make it possible to use a random number generator in a fashion more
like rand() for the cases where that's preferable, and for a lot of cases,
having the range API is _extremely_ useful.

- Jonathan M Davis



More information about the Digitalmars-d mailing list