Hi, I am writing a program to generate 6 random numbers from 1 to 40 inclusive.
So far, I have been using the code below..
However, the only problem is that from time to time, I'm getting repeating numbers.
Is there any way to solve this issue???
Here's the code:
Code:
# define M 6
int main()
{
int j;
int m_num[j];
time_t seconds;
int lower=1;
int upper=40;
time(&seconds);
srand((unsigned int)seconds);
for(j=0; j<M; j++)
{
m_num[j]=rand()%(upper-lower+1)+1;
}
printf("Generated numbers are:");
for(j=0; j<M; j++)
{
printf(" \n %d \n", m_num[j]);
}
system("PAUSE");
return 0;
}
note: i'm using Dev c++, and also Visual Studio sometimes..