This code generates a unique random number only once and stores it in random_once[i] .
In the first for loop, an ad is created in which a random number is stored.
The second for loop is used to get pre-rendered random numbers stored in the random_once[i] array.
Yes, generating 100001 random numbers will take several hours, if not days.
#include <ctime> #include <iostream> using namespace std; int main() { int numUnigram = 3001; int size=numUnigram; int random_once[100001]; cout<<"Please wait: Generatng "<<numUnigram<<" random numbers "; std::cout << '-' << std::flush; srand(time(0)); for (int i=0;i<size;i++) { //This code generates a unique random number only once //and stores it in random_once[i] random_once[i]=rand() % size; for(int j=0;j<i;j++) if (random_once[j]==random_once[i]) i--; //loading animation std::cout << "\b\\" << std::flush; std::cout << "\b|" << std::flush; std::cout << "\b/" << std::flush; std::cout << "\b-" << std::flush; } cout<<" \n"; // this code dispays unique random numbers stored in random_once[i] for ( i=0;i<size;i++) cout<<" "<<random_once[i]<<"\t"; cout<<" \n"; return 0; }
source share