This question already has an answer here:
How can I get random numbers 0 to 10^9 (without duplicate ) and store them in an arry .First of all I faced problem to create an arry of size 10^9(i can declare up to int arry[10^8] ) and store random numbers without duplicate in it.
#include<bits/stdc++.h>
using namespace std;
#define S 100000000
int main()
{
int i;
std::vector<int>result(S);
for( i = 1; i < S ; ++i)
{
int t = rand() % i; // t - is random value in [0..i)
result[i] = result[t]; // i-th element assigned random index-th value
result[t] =i; // and, random position assigned i value
}
}
Is there any process to get random numbers 0 to 10^9 and store them in an arry
Aucun commentaire:
Enregistrer un commentaire