Thread overview
Randomisation of array order
Aug 02, 2015
Matt
Aug 02, 2015
Matt
Aug 02, 2015
cym13
August 02, 2015
I was planning to use a dynamic array of indices to represent a deck of cards, and was wondering if there was any easy way to "shuffle" the arrays contents? I checked the library docs, but came to the conclusion that sorting arrays is a much more common operation :)

If anyone has a suggestion on a good way to implement this, I'd appreciate it. I don't need you to code it for me ( although I wouldn't turn it down if you've already done it), just a suggestion of what to do would be appreciated
August 02, 2015
...And then I realised that I hadn't looked inside std.random.

Question solved, because I am a dumbass.
August 02, 2015
On Sunday, 2 August 2015 at 09:24:12 UTC, Matt wrote:
> I was planning to use a dynamic array of indices to represent a deck of cards, and was wondering if there was any easy way to "shuffle" the arrays contents? I checked the library docs, but came to the conclusion that sorting arrays is a much more common operation :)
>
> If anyone has a suggestion on a good way to implement this, I'd appreciate it. I don't need you to code it for me ( although I wouldn't turn it down if you've already done it), just a suggestion of what to do would be appreciated

Have you checked std.random ?

    import std.random, std.stdio;

    void main() {
        auto arr = [1, 2, 3, 4, 5];
        arr.randomShuffle;
        arr.writeln;
    }