fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <random>
  4. #include <algorithm>
  5.  
  6. std::vector<int> MakeRndArray(int Min, int Max, int Count, bool IsSort = false){
  7. std::random_device rd;
  8. std::mt19937 mt(rd());
  9. std::uniform_int_distribution<> uid(Min, Max);
  10. std::vector<int> vec(Count);
  11.  
  12. for (auto& o : vec) o = uid(mt);
  13.  
  14. if (IsSort == true) std::sort(vec.begin(), vec.end());
  15.  
  16. return vec;
  17. }
  18.  
  19. int main(){
  20.  
  21. auto A = MakeRndArray(1, 16, 4, true);
  22. std::cout <<"First:" << '[';
  23. for (auto& o : A) std::cout << o << ',';
  24. std::cout << ']';
  25. std::cout << std::endl;
  26. while (std::next_permutation(A.begin(), A.end()))
  27. {
  28. std::cout << '[';
  29. for (auto& o : A) std::cout << o << ',';
  30. std::cout << ']';
  31. std::cout << std::endl;
  32. }
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
First:[4,5,11,13,]
[4,5,13,11,]
[4,11,5,13,]
[4,11,13,5,]
[4,13,5,11,]
[4,13,11,5,]
[5,4,11,13,]
[5,4,13,11,]
[5,11,4,13,]
[5,11,13,4,]
[5,13,4,11,]
[5,13,11,4,]
[11,4,5,13,]
[11,4,13,5,]
[11,5,4,13,]
[11,5,13,4,]
[11,13,4,5,]
[11,13,5,4,]
[13,4,5,11,]
[13,4,11,5,]
[13,5,4,11,]
[13,5,11,4,]
[13,11,4,5,]
[13,11,5,4,]