0

Hi am new to programming and I really need some how to check an array to see if a number already exists. I read the tutorials about random number genertors but I am just not getting how to check if the random generator already generated that number somewhere else in the array.

Thanks,

Laurie

2
Contributors
1
Reply
2
Views
13 Years
Discussion Span
Last Post by Narue
0

You can search for a number easily:

int array[BIG_SIZE];
int n = 0;

// ...

int r = rand();
int i;

for ( i = 0; i < n; i++ ) {
  if ( r == array[i] )
    break;
}

if ( i == n )
  array[n++] = r;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.