# Instantiate & Random.Range

In my code i have a private variable that picks a Random number from either 1 or 2.

``````private int random = Random.Range(1,2);
``````

But to no avail i cannot seem to have one of the five clones i have spawned with Instantiate to get the Random number 2. I expected at least 2 of the clones to pick 2, yet all five pick the random number 1 and i have tested it three times. There is no way i can be that lucky.

``````if (random == 1)
{
if (timer > 140)
{
float x = transform.position.x;
float y = transform.position.y;
Vector3 pos;

pos = new Vector3(x -= 0.5f, y += 1, transform.position.z);
transform.position = pos;
}

if (timer < 140)
{
float x = transform.position.x;
float y = transform.position.y;
Vector3 pos;

pos = new Vector3(x -= 0.25f, y -= 1, transform.position.z);
transform.position = pos;
}
}

if (random == 2)
{
if (timer > 140)
{
float x = transform.position.x;
float y = transform.position.y;
Vector3 pos;

pos = new Vector3(x += 0.5f, y += 1.5f, transform.position.z);
transform.position = pos;
}

if (timer < 140)
{
float x = transform.position.x;
float y = transform.position.y;
Vector3 pos;

pos = new Vector3(x += 0.25f, y -= 1, transform.position.z);
transform.position = pos;
}
}
``````

Hope someone could help =)

Random.Range(1,2); will always return 1

``````Random.Range(1,3); will return the value 1 or 2
``````

Check the documentation :

Returns a random integer number between min [inclusive] and max [exclusive]

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

use Random.Range(1,3)

For Int Random.Range never return value “to”, so you need write Random.Range(min val, max val+1)

thank you so much