i want to generate non repeated random numbers from 0 to 156. here is the code for the purpose. but when i try to generate the random numbers more then 1 time by using a for loop, the same pattern on numbers repeats. how to solve this problem ?
#include "sys/types.h"
#include "stdio.h"
#include "time.h"
#define MAX 2000
#define N 156
main( )
{
int array[BIG_SIZE],r;
int n = 0; int count_check,count_gen ,i;
time_t t1;
(void) time(&t1);
srand48((long) t1);
for (count_gen=0;count_gen<=MAX;count_gen++)
{
r = lrand48()%N;
for ( count_check = 0; count_check < n; count_check++ )
{
if ( r == array[count_check] )break;
}
if ( count_check == n ) array[n++] = r;
}
for(i=0;i<N;i++)
printf("%d\n",array[i]);
}
regards
xshashiy