Selecting Random Object and Setting Variable to True

Hello guys, so for my game I need a random object to be selected. It's not exactly how it sounds. What I have in my script is "var CPU : AIScript[]"

So all the CPU/AI objects that have the script "AIScript" are all in one array.

Then what I need is to randomly select one of those objects in the array. The "AIScript" has a variable "var Tagged : boolean = false"

What I need is for the script to randomly select an object in the array, and within that object, make sure that Tagged = true.

I'm guessing there's an easy way to do this but right now I'm stuck :P

Thanks In Advance!

You can do something like this, if I understand the question correctly:

// Get random index
var randomIndex : int = Random.Range(0, CPU.Length);
// Set its tagged value to true
CPU[randomIndex].Tagged = true;

Probably something like this:

randomAI = CPU[Random.Range(0,CPU.length)];
randomAI.GetComponent(AIScript).Tagged = true;