int count = 10 ; int [] array = new int [count]; for ( int i = 0 ; i < array.Length; i ++ ) array[i] = - 1 ; for ( int i = 0 ; i < count; i ++ ) ... { int found = 0; int index = random.Next(count); int j; for(j = index; j < count; j++) ...{ if( array[j] == -1) ...{ array[j] = i; found = 1; break; } } for(j = 0; found == 0 && j < count; j++) ...{ if( array[j] == -1) ...{ array[j] = i; break; } } }