randomSample
David Held via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 17 21:23:50 PDT 2014
On 5/17/2014 9:18 PM, David Held wrote:
> How do I get an array from randomSample()?
>
> int[] source = [ ... ];
> int[] sample = randomSample(source, 3);
>
> src\main.d(30): Error: cannot implicitly convert expression
> (randomSample(source, 3u)) of type RandomSample!(int[], void) to int[]
> [...]
Even worse, foreach is brittle:
foreach (i, a; randomSample(source, 3))
src\main.d(30): Error: cannot infer argument types
If I remove the index variable, it works. But I really need the index too.
Dave
More information about the Digitalmars-d-learn
mailing list