Sort in return statement
codephantom
me at noyb.com
Sat Dec 9 07:06:10 UTC 2017
On Saturday, 9 December 2017 at 04:31:33 UTC, SimonN wrote:
>
> Yes, this works, and your algorithm would even accept arbitary
> random-access ranges, not merely arrays.
>
Would be nice if I could do it all as a 'one liner':
// --------
int[] draw8Numbers()
{
import std.algorithm.sorting : sort;
import std.random : randomShuffle;
import std.meta : aliasSeqOf;
import std.range : iota;
import std.range : take;
import std.array : array;
// return a sorted array of 8 random numbers, between 1..45
inclusive.
return sort(randomShuffle([ aliasSeqOf!(iota(1,46))
]).take(8)).array;
}
// -------
More information about the Digitalmars-d-learn
mailing list