#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstdlib>
#include <ctime>

int main () {
    std::srand(std::time(NULL)); // initialize random seed

    // shuffle a 2D array
    int arr[3][3] = {
        {0, 1, 2},
        {3, 4, 5},
        {6, 7, 8}
    };

    // Shuffle from the first member to the last member.
    // The array is interpreted as a 9 element 1D array.
    std::random_shuffle(&arr[0][0], &arr[2][3]);

    // print the result
    for (int row = 0; row < 3; ++row) {
        for (int col = 0; col < 3; ++col) {
            std::cout << arr[row][col] << ' ';
        }
        std::cout << std::endl;
    }
    return 0;
}