fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <random>
  4. using namespace std;
  5.  
  6. int main() {
  7. vector<int> listOfNumbers;
  8. const int maxOfNumbers = 100;
  9. const int howManyNumbersToSelect = 6;
  10. for (int index = 0; index < maxOfNumbers; index++)
  11. {
  12. listOfNumbers.push_back(index);
  13. }
  14.  
  15. std::random_device rd;
  16. std::mt19937 mt(rd());
  17. std::uniform_int_distribution<> dist(1, maxOfNumbers);
  18.  
  19. for(int index = 0; index < howManyNumbersToSelect; index++)
  20. {
  21. int randomNumber = dist(mt) - 1; //because of indexing
  22. cout << listOfNumbers[randomNumber] << " ";
  23. listOfNumbers.erase(listOfNumbers.begin() + randomNumber);
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
35 42 45 78 43 56