generate an array of 100 uniform distributed numbers

ddos via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 22 11:26:44 PST 2015


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?

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?

finally i got it working with this:
auto t = [0,1,2].map!(v => uniform(0.0,1.0));
writeln(t);

seems pretty easy eh? d is bugging me alot like this ^_^ but i 
love it's syntax


More information about the Digitalmars-d-learn mailing list