Shuffle deck

How do I use the rand function to shuffle integers from 1-52?

I have an array which stores values 1-52, but then outputting it in random order? is there an opposite function to sort?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <random>
#include <algorithm>
#include <iterator>

int main()
{
    int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ;

    // http://en.cppreference.com/w/cpp/numeric/random
    static std::mt19937 rng( std::random_device{}() ) ; // random number engine

    for( int i = 0 ; i < 5 ; ++i )
    {
        // http://en.cppreference.com/w/cpp/algorithm/random_shuffle
        std::shuffle( std::begin(a), std::end(a), rng ) ;
        for( int v : a ) std::cout << v << ' ' ;
        std::cout << '\n' ;
    }
}

http://coliru.stacked-crooked.com/a/4aa4443abd2a1a94
Topic archived. No new replies allowed.