randomShuffle

maarten van damme maartenvd1994 at gmail.com
Mon Jun 3 03:01:41 PDT 2013


How about using std.random.randomSample?


2013/6/3 Yann <skratchie at gmx.de>

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130603/9e4876f3/attachment.html>


More information about the Digitalmars-d-learn mailing list