How to generate a random int that does not repeat consecutively?

Here 's my code. This is designed to get an integer to get the element of an array and use the string as Tags for spawning an object. However, my problem is it usually repeats the random int 3 times. I wanted to limit the repetition to 2 times consecutively only.

private string[] FirstTags = new string[3]
    {
        "a", "b", "c"
    };

private string[] SecondTags = new string[5]
    {
        "v", "w", "x", "y", "z"
    }

    int randomInt_FirstTags;
    int randomInt_SecondTags;

void GetRandomTag()
    {
        randomInt_FirstTags = Random.Range(0, FirstTags.Length);
        randomInt_SecondTags = Random.Range(0, SecondTags.Length);
    }

This code is where I call GetRandomTag() and spawn my objects. It is called every time the player scores.

    public IEnumerator SpawnObjects()
        {
            GetRandomTag();
            yield return new WaitForSeconds(0.8f);
            SpawnFirstTags();
            SpawnSecondTags();
        }

I’m still a newbie in programming so bare with my codes. I badly need help with this. Thank you in advance!! :slight_smile:

Well you could have another int called PreviousInt, which would be set to the random int generated every time. Then, if the int generated equals the PreviousInt (meaning that you generated the same number twice in a row), then you can keep regenerating the number until it equals something different. For example:

    int PreviousWord;

    void NewWord()
    {
            Start:

            int RandomWord = Random.Range(0, 10);

            if (RandomWord == PreviousWord)
            {
                goto Start;
            }
            else
            {
                PreviousWord = RandomWord;

                //Add any function that occurs from the Randomly generated int
            }
    }

@zcndev