Random Numbers but no duplicits

I am trying to create 3 random numbers with no doubles. i am using this code:

for (i=0; i<10; i++) {
 temp_array.push(i);
}
for (j=0; j<3; j++) {
 var index:Number = Math.floor(Math.random()*temp_array.length);
 choosenNumbers.push(temp_array[index]);
 temp_array.splice(index, 1);
}
trace(choosenNumbers);

I get the random numbers I want but I seem to get doubles quite a bit. Any help???

var arr:Array = [1,2,3,4,5,6,7,8,9]
arr.sort(shuffle);
trace(arr);

function shuffle():Number {
	return Math.floor(Math.random() * 3) - 1;
}

You should be able to modify the script so that it fits your needs. Basically, just put the possible numbers in the array, sort it using shuffle, and pick any 3 elements in the array and they will be pseudo-random.

Yes I see how that could work, the problem i run into is that i am going to be adding to this array for pretty much ever… With this script i forgot to mention that i want to pull the max number from an array that has other info pertaining to the videos i want to display. so i was hoping that every time i added a new element to my video array i wouldn’t have to add another number…

In that case, you could try making another array (or assigning a property on the existing element, if the datatype allows that) that would keep track of which videos had been played already, and then check that value when randomly selecting a video.

Would it be possible for you to kick the already selected elements out of the array? That would make it easier for you to code something to select one randomly.

Whats happening is i have a video play and then after its done three thumbnail images come up and after 5 seconds 3 new ones come up. so what i have that random number generator doing is pick 3 numbers from the list of numbers that is made. If i get 1,4,8 that is fine the problem i am running into is i will get 1,4,1. When I get the two 1’s i am basically linking to the same video and that looks bad. So i need to find out how to make sure i get 3 totally different number at a time and then after that do it a gain 5 seconds later.