not so randomly choosing the same number every time with Random.Range();

I’m a little stumped as to how Random works behind the curtains. My script sets the same value ( int 1) to direction every time its called. The if Random.Range(0,100) works just fine. I’ve considered breaking the script into 2 parts (one for left one for right) instead of pulling it all under that if, but I could still use a bit of an explanation as to why this is happening. Mahalo

 if (Random.Range(0, 100) == 1)
            {
                direction = 0;
                direction = Random.Range(1, 2);
                if (direction == 2) direction = -1;
                Debug.Log(direction);
                speed = Random.Range(0.1f, 0.2f);
                DestroyOldBody();
                CreateNewBody();
            }

From Official Docs:

public static int Range(int min, int max);
Description

Returns a random integer number between min [inclusive] and max [exclusive] (Read Only).

Note that max is exclusive, so using Random.Range( 0, 10 ) will return values between 0 and 9. If max equals min, min will be returned.

Meaning, Random.Range(1,2) will never return 2. My advice is to just log these things that confuse you and you figure it out really fast :slight_smile: