You need to call srand()
before you call rand()
to initialize the random number generator.
You can try srand( time( NULL ) )
which will give you a different result once per second. If you need it to be more variable than that, then you will have to come up with a better way to seed the number generator.
int i,numberToBeFound;
int SIZE;
int *array2;
srand( time( NULL ) );
SIZE=(rand()%100)+1; // size can be in the range [1 to 100]
array2 = malloc(sizeof(int)*SIZE);
for(i=0;i<SIZE;i++) //fill the array with random numbers
array2[i]=rand()%100;
PS: You should not cast malloc()
in C -- see this post.