Avoid getting same object as previous one with Random.Range?

Hey guys, been working with Random.Range today and I am trying to avoid getting the same result as the previous one when i randomly select an object from an array, here is the code:

var myArray : GameObject[]; //array

function Start (){	
myArray = gameObject.FindGameObjectsWithTag ("point");//fill array with objects     
}

function Update(){
if (Input.GetButtonDown("Fire1")){
RandomPick();
}
}

function RandomPick(){
var myIndex = Random.Range(0, myArray.length);//randomly pick an object
Debug.Log(myArray[myIndex]);//output selected object
}

What would be the simplest way of preventing myIndex from selecting the same object as the previous one?

Remove it from the array? Other than that what you want isn’t really random…

My JS is rusty to be fair haha!

 function RandomPick(){

         var myIndex = Random.Range(0, myArray.length);//randomly pick an object
         Debug.Log(myArray[myIndex]);//output selected object

         myArray.splice(myIndex,1); //removes the index:myIndex
 }

So yeah splice does the work here:

 splice(index, numberOfTimes);

index = The index of the element you want to remove
numberOfTimes = Number of items to be removed - 0 results in 0 items being removed.

If you want to store the object you just removed instead of ‘just’ removing it, simply add:

 var x = myArray.splice(myIndex,1);

I would solve it like this if it is just the last value you do not want repeated.

var myArray : GameObject[]; //array
// Keep track of last selected index
var previousPick = -1; 
function Start () {    
    myArray = gameObject.FindGameObjectsWithTag ("point");
 }
 
function RandomPick(){
    var myIndex = previousPick;
  // loop until the random value does not match last one
   while(myIndex == previousPick)
    {
        myIndex = Random.Range(0, myArray.length);
    }
   // update last one.
    previousIndex = myIndex;
}