Generate array of random values

Jesse Phillips jessekphillips+d at gmail.com
Mon Aug 1 21:42:09 PDT 2011


On Tue, 02 Aug 2011 03:48:03 +0200, David Nadlinger wrote:

> On 8/2/11 3:40 AM, Jesse Phillips wrote:
>> Andrej Mitrovic Wrote:
>>> Is there a simpler way to do get an array of random values?
>>
>> Untested:
>>
>> auto arr = new int[1024];
>> fill(arr, uniform(0, 1024));
> 
> This does a great job of creating an array containing the same random
> value 1024 times. ;)
> 
> David

Fine, let me provide a tested one:

import std.algorithm;
import std.array;
import std.random;
import std.range;

void main()
{
    auto arr = new int[1024];
    fill(arr, randomCover(iota(0,1024), rndGen));
}


Knew I had done something with fill before.


More information about the Digitalmars-d-learn mailing list