fork(1) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int main() {
  7. int lottoNums[5];
  8.  
  9. int numsToChooseFrom[35];
  10. int numsAvailable;
  11. int chosenIndex;
  12.  
  13. srand(time(0));
  14.  
  15. for(int set = 0; set < 10; ++set){
  16.  
  17. for(int i = 0; i < 35; ++i){
  18. numsToChooseFrom[i] = i + 1;
  19. }
  20. numsAvailable = 35;
  21.  
  22. for(int i = 0; i < 5; ++i){
  23. chosenIndex = rand() % numsAvailable;
  24. lottoNums[i] = numsToChooseFrom[chosenIndex];
  25.  
  26. for (int j = chosenIndex+1; j < numsAvailable; ++j) {
  27. numsToChooseFrom[j-1] = numsToChooseFrom[j];
  28. }
  29. --numsAvailable;
  30. }
  31.  
  32. for(int i = 0; i < 5; ++i){
  33. cout << lottoNums[i] << " ";
  34. }
  35. cout << endl;
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
16 26 7 14 4 
5 12 17 26 25 
10 28 5 12 11 
18 4 24 34 9 
17 3 31 35 30 
34 11 29 25 15 
14 10 1 15 30 
6 27 11 32 8 
34 30 14 6 21 
29 20 11 15 12