int main()
{ srand(time(0));
int term;
cin>>term;
int a[term];
int b;
for(int i=0;i<term;i++)
{
int count=0;
b=(rand()%term);
for(int k=0;k<100;k++)
{
if(count<term)
{
if(b!=a[k])
{
a[i]=b;
count++;
}
}
}
}
for(int k=0;k<4;k++)
{
cout<<a[k]<<endl;
}
}Put the code you need help with here.
From you code, you want a
-unqiue number width "term" number of digits. (line 5)
-Also, you want the max digit of the unique number to be < term. (line 10).
Hence, you are simply generating a random "term-1" digit number from [0 to term-1].
e.g When "term" is 4, you could get [0123] or [2310] etc...
If this is really what you want, you can just fill an array with digits from 0 to term -1 and do a random shuffle.
1 2 3 4
int a[term];
for(int i = 0; i < term; i++)
a[i] = i;
std::random_shuffle(a,a+term);