How to instantiate the first 8 gameobjects in an array (UnityScript)?

Hi,
I’m making a simple random generation script. Right now the script has 2 arrays: one for the objects it should spawn and another for the spawn locations. I’ve made it so that at the start of the level, the script shuffles the “objects to spawn” array, so the order is randomized. Then the script should spawn the objects (rooms) to the spawnpoints.

The thing I can’t figure out is how to spawn (instantiate) just the first 8 gameobjects of the shuffled array. Right now the SpawnRooms function spawns random objects between 0 and 7 in the array until the spawn points are filled, but what I’d want for it to do is spawn the first 8 in the array (or element 0, 1, 2, 3, 4, 5, 6 and 7) The goal is to never spawn the same room twice, which would happen with shuffle array → spawn the first 8 objects.

my code:

var objectsToSpawn = new GameObject[12];
var spawnLocations = new Transform[8];
 
function Start(){
	Shuffle();
	SpawnRooms();
}


function Shuffle() {
	for (i = 0; i < objectsToSpawn.Length; i++) {
		var temp = objectsToSpawn*;*
  •  var randomIndex = Random.Range(0, objectsToSpawn.Length);*
    

_ objectsToSpawn = objectsToSpawn[randomIndex];_
* objectsToSpawn[randomIndex] = temp;*
* }*
}

function SpawnRooms(){

for (var i=0; i < spawnLocations.length; i++){

var thingToSpawn : int = Random.Range( 0, 7);

Instantiate( objectsToSpawn[thingToSpawn], spawnLocations*.position, transform.rotation );*

}
}

Since you are shuffling the array, you don’t need to generate random values in this funciton. Try:

function SpawnRooms(){
 
  for (var i=0; i < spawnLocations.length; i++){
    Instantiate( objectsToSpawn_, spawnLocations*.position, transform.rotation*_ 

}
}