Random number generator not generating numbers

I’m making a boss enemy for my fps that has two attacks that he will choose from at random When the timer = the fire rate, the enemy should generate a number that will be the attack. But for some reason, the enemy won’t generate a number. Here’s the Code

#pragma strict
var health : int;
var biteDamage : int;
var enemyChoice : int;

var fireRate : float;
var fireTimeRemaining : float;

var player : Transform;

var agent : NavMeshAgent;

var animationThing : Animation;

var attacking : boolean; 

function Start () 
{
	animationThing = GetComponent(Animation);
	agent = GetComponent(NavMeshAgent);
	player = GameObject.FindWithTag("PlayerDetection").transform;
}

function Awake()
{
	attacking = true;
	animationThing.Play("Armature|roar");
	fireTimeRemaining = fireRate;
}

function Update () 
{
	fireTimeRemaining -= Time.deltaTime;
	
	if(!animationThing.IsPlaying("Armature|roar") || !attacking)
	{
		attacking = false;
		agent.destination = player.position;
		animationThing.Play("Armature|walk");
	}
	
	if(fireTimeRemaining <= 0)
	{
		fireTimeRemaining = fireRate;
	}
	
	if(fireTimeRemaining == fireRate)
	{
		var randomAttack = Random.Range(0,2);
		
		attacking = true;
		enemyChoice = randomAttack;
	
		Debug.Log("attacked");
	}
}

While the above code should technically work, it’s probably safer and better practice to shift that into a function.

     if(fireTimeRemaining <= 0)
     {
         ResetFireRate();
     }
     

function ResetFireRate()
{
  fireTimeRemaining = fireRate;
  var randomAttack = Random.Range(0,2);
         
  attacking = true;
  enemyChoice = randomAttack;
     
  Debug.Log("attacked");
  //You should also debug this to make sure it works
  Debug.Log(randomAttack);
}

Also look at the API documentation for Random.Range here. Note that with integegers, max value is never returned. You’ll only ever get 0 or 1. Part of the reason for the exclusion of the max value is because when you want to do array[randomInt] you can just plug in the length without worrying about an index higher than length.

If you want 2 to be included, either do Random.Range(0, 3); or do the inclusive float range Random.Range(0.0, 2.0); Then just round to nearest int. If the problem persists, you might want to look into Random.seed or Random.value

The logic in your last two blocks looks iffy. Try replacing them with:

 if(fireTimeRemaining <= 0)
 {
     var randomAttack = Random.Range(0,2);
  
     attacking = true;
     enemyChoice = randomAttack;
 
     Debug.Log("attacked");

     fireTimeRemaining = fireRate;
 }