generate an array of 100 uniform distributed numbers

Vladimir Panteleev via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 22 11:32:40 PST 2015


On Thursday, 22 January 2015 at 19:26:46 UTC, ddos wrote:
> hi guys, firstly this has no direct application, i'm just 
> playing around and learning
>
> i want to create 100 uniform distributed numbers and print them
> my first attempt, just written by intuition:
> [0 .. 100].map!(v => uniform(0.0, 1.0).writeln);
>
> i found out i can't write [0 .. 100] to define a simple number 
> range, but is there a function to do so?

Yes! iota(100)

> second attempt, replacing the range with an simple array
> [0,1,2].map!(v => uniform(0.0,1.0).writeln);
> this does compile and run, but doesn't print anything, just an 
> empty string, why is that?

Maybe you meant to put the .writeln outside of the parens? Since 
map is lazily evaluated, writeln is never called and the entire 
expression does  nothing.


More information about the Digitalmars-d-learn mailing list