randomShuffle

Yann skratchie at gmx.de
Mon Jun 3 01:48:36 PDT 2013


Hey,

I am trying to generate an array of 10 unique (!) random numbers 
from 1 to 1000 each (for example). The best I could come up with 
is:

auto arr = iota(1, 1000).array;
randomShuffle(arr);
return arr.take(10).array.sort;

This leaves me quite unhappy, because I would like the code
a) to be one line
b) not use "array" more than once

Is there a better way to accomplish this? Naively, I would expect 
something like
"return iota(1, 1000).randomShuffle.take(10).sort;"

Thanks,
Yann


More information about the Digitalmars-d-learn mailing list