random number without repeating

hello, i created a method who choose a random number, but in some cases generate an infinite loop, i don’t know why after repeating Random Range 6 times in the loop, the loop become infinit.

public int initialSceneIndex = 6;
public int lastSceneIndex = 15;
public int[] scenesSelected = new int[] {6,7,8,9,10,11,12,13,14};

public int GetRandomWorldSceneIndex()
{
  
   int u = Random.Range(initialSceneIndex, lastSceneIndex + 1);
   int j = 0;
    
    for (int i = 0; i < scenesSelected.Length; i++) 
    {
        j++;
        if (j >= 30)
        {
            Debug.Log("infinite");
            break;
        }
      
        if (u != scenesSelected*)*

{

continue;
}
else
{
u = Random.Range(initialSceneIndex, lastSceneIndex + 1);
i = -1;
Debug.Log(“repeat”);

}
}
return u;
}
i think in this case the answer always should be 15, the infinite loop only created when " Debug.Log(“repeat”)" is more than 6

Watch out line 28.
You write i = -1 instead of i –