randomShuffle

Yann skratchie at gmx.de
Mon Jun 3 03:10:14 PDT 2013


Thanks a lot for the suggestions!

Cheers,
Yann

On Monday, 3 June 2013 at 10:06:30 UTC, bearophile wrote:
> Yann:
>
>> Is there a better way to accomplish this? Naively, I would 
>> expect something like
>> "return iota(1, 1000).randomShuffle.take(10).sort;"
>
> Two ways, the first gives items in random order, the second 
> ordered as you seem to desire:
>
> import std.stdio, std.random, std.range, std.array;
> void main() {
>     iota(1, 1001).randomCover(rndGen).take(10).writeln;
>     iota(1, 1001).randomSample(10).writeln;
> }
>
>
> But be careful with randomCover, because maybe it takes the rnd 
> generator by value.
>
> Bye,
> bearophile



More information about the Digitalmars-d-learn mailing list