[Solved] Generate 10 unique integers in C# for Unity


Is this what you’re trying to say? If not, please specify how you mean further. This code should give you a number between 1-10 that hasn’t been already used. This code will only work 10 times.

Random rnd = new Random();
List<int> usedNumbers = new List<int>();


public int RandomNum(){
    int number;
    do {
        number = rnd.Next(1, 10);
    } while(usedNumbers.IndexOf(number) == -1);

    usedNumbers.Add(number);

    return number;
}

solved Generate 10 unique integers in C# for Unity