Generate array of random values

Jesse Phillips jessekphillips+D at gmail.com
Mon Aug 1 18:40:02 PDT 2011


Andrej Mitrovic Wrote:

> I'm currently using this:
> 
> import std.algorithm;
> import std.array;
> import std.random;
> import std.range;
> 
> void main()
> {
>     auto arr2 = array(map!( (int){ return uniform(0, 1024); })(iota(0, 1024)));
> }
> 
> Is there a simpler way to do get an array of random values?

Untested:

auto arr = new int[1024];
fill(arr, uniform(0, 1024));


More information about the Digitalmars-d-learn mailing list