vendredi 14 août 2020

How to generate random unique integers [duplicate]

#include <ctime>
#include <iostream>
#include <cstdlib>

using namespace std;
int main(){
    srand(time(0));
    for(int i = 0; i < 4; i++){
        cout << 1+(rand()%6) << endl;
    }
    
   return 0;
}

The above code generates random numbers. However, I want these numbers to be unique. Please could anyone help me, thank you.




Aucun commentaire:

Enregistrer un commentaire