Random.Range always returns min value (didn't set seed)

using UnityEngine;
using System.Collections;

public class PrefabSpawn : MonoBehaviour {

public GameObject[] items;
int X = Random.Range(0,2);

void Awake()
{
	Instantiate (items[X], new Vector3(0,0,0), Quaternion.identity);
}

void Update () {

}

}

Here’s my code, it’s supposed to spawn a prefab from a table, but it always spawns the one stored in items[0]. I found similar questions, but it is a seed problem, and I don’t think it can fit my problem cause I’m not setting seed.

Correct initialization your variable “X”. Change code:

 public GameObject[] items;
 int X = 0;

 void Awake() {
  X = Random.Range(0,2); //Gets int value from 0 to 1
  Instantiate (items[X], new Vector3(0,0,0), Quaternion.identity);
 }

I hope that it wil help you.

Hi, as per Unity Random.Range for int, the function works with maxValue exclusive. That is unityMaxValue = yourMaxValue + 1