Generate array of random values

Jonathan M Davis jmdavisProg at gmx.com
Mon Aug 1 14:53:28 PDT 2011


> On 01.08.2011 23:43, Andrej Mitrovic wrote:
> > Actually I don't really need *uniform* distribution, it's just that
> > when porting C code to D I didn't find any obvious random()/rnd()
> > functions, and uniform seemed to be the closest thing without having
> > to mess around with a bunch of randomization parameters which I don't
> > care about.
> > 
> > I don't see how we can claim D to be an elegant language with this mess:
> > array(map!"a % 1024"(take(rndGen(), 1024)))
> > 
> > That's just damn *horrible*.
> 
> Dunno maybe it's only me, but some years ago when I used C++98 & STL
> extensively I would find this line a very simple and clean solution. Now
> time is changing and so on...
> A thought - would amap as a shorthand for array(map... float your boat?
> One pair of parens off.

Yeah. I confess that I don't see much ugly in that solution. It wouldn't hurt 
my feelings any to have a cleaner solution, but

array(map!"a % 1024"(take(rndGen(), 1024)));

seems fine to me. But maybe I'm just too used to the STL and std.algorithm. 
Regardless, it's _way_ cleaner than what you can achieve in C++98 trying to do 
the same thing.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list