I already searched for this question but none of the solutions I found helped. Maybe somebody can help me.
I have the following loop:
private static readonly Random RANDOM = new Random();
...
int[] array; // is initialized, when used. ;)
if (array.Sum() != 0)
{
int j = 0;
do {
j = RANDOM.Next(8);
} while (array[j] == 0);
}
This whole loop is in another loop which, again, is in a Parallel.Foreach
-loop.
It seems, that j
is always 0
. Most times it is not noticeable, but if array[0] == 0
, then it won't get out of the loop.
I got the suspicion that the do-while
-loop might be to fast. But also after some seconds (~30) it does not leave the loop. So the Random
does not seem to return a new or different value (even in the same thread).
I also tried this solution but with no effect.