If you use rand() it is possible that you could have the same number appear more then once in your array. In that case looping through the array will only detect the first occurance of that number in the array.