fork download
  1. #include <algorithm>
  2. #include <random>
  3. #include <ctime>
  4. #include <cstdlib>
  5. #include <iostream>
  6. #include <iomanip>
  7.  
  8. int main()
  9. {
  10. constexpr std::size_t N = 6 ;
  11. int a[N][N] ;
  12. auto begin = std::begin( a[0] ) ;
  13. auto end = std::end( a[N-1] ) ;
  14.  
  15. std::iota( begin, end, 1 ) ;
  16. std::srand( std::time(nullptr) ) ;
  17. std::seed_seq seed_seq { std::rand(), std::rand(), std::rand(), std::rand() } ;
  18. std::shuffle( begin, end, std::mt19937(seed_seq) ) ;
  19.  
  20. for( const auto& row : a )
  21. {
  22. for( int i : row ) std::cout << std::setw(3) << i ;
  23. std::cout << '\n' ;
  24. }
  25. }
  26.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
 11 31 10 25 13 20
 24 15 22  5 18 17
 29 32 35  4  1 36
 14  7  2  8 16 26
 19  3 33 23 30 12
 28 21  6  9 27 34