FYI: the random number generator that comes with the compiler is not really random enough.
you have two nested loops, and if size is big enough, you can run out of new random numbers after some iterations of the outer loop.
secondly, i can't see why you need the inner loop, the outer is sufficient.
and i can't understand the purpose of the condition in the if statement.
i might be able to help out if you clear your intentions in this code.