- I've Implemented a very simple non repeated random generator and I want to share it for anyone ..
- I want Your Opinions Please , and any comments about my code
- Anyone notice any fault in the result (any repeated numbers), please report me
- Thank You Very Much
- ENJOY :D
#include <iostream>
#include <ctime>
using namespace std;
bool isContained(int arr[],int n,int x)
{
for(int i=0;i<n;i++)
{
if(arr[i]==x)
return true;
}
return false;
}
int main()
{
srand(time(0));
const int x = 100;
int r[x];
for(int i=0;i<x;i++)
{
r[i]=1+rand()%x;
while(isContained(r,i,r[i]))
{
r[i]=1+rand()%x;
}
}
for(int i=0;i<x;i++)
cout<<r[i]<<"\n";
cout<<"\n\n";
return 0;
}
- I don't Know if this code was implmented before