# Randomly Generate 3 unique numbers

**URL:** https://forum.kirupa.com/t/randomly-generate-3-unique-numbers/262121
**Category:** flash
**Created:** [June 3, 2008, 3:05pm UTC](https://forum.kirupa.com/t/randomly-generate-3-unique-numbers/262121 "2008-06-03T15:05:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![brostd](https://avatars.discourse-cdn.com/v4/letter/b/c6cbf5/32.png) [@brostd](https://forum.kirupa.com/u/brostd)
#### Post date: [June 3, 2008, 3:05pm UTC](https://forum.kirupa.com/t/randomly-generate-3-unique-numbers/262121/1 "2008-06-03T15:05:03Z")

</div>

I need to generate 3 unique numbers that will allow me to call from an array that has a list of FLVs with links, title and maybe a description. I know how to make random numbers but i need to know how to make sure that they are not doubling up so i can have [1,8,0] but not [1,8,1]. i will attach all my files and let someone take a look and see if they understand what i am doing.

What i am trying to do is in the chooser.fla is randomly fill the empty movieClips and then i want to build in a timer that will refresh the movieClips with fresh images.

---

<div class="post-metadata">

### Author: ![neilmmm](https://avatars.discourse-cdn.com/v4/letter/n/ee7513/32.png) [@neilmmm](https://forum.kirupa.com/u/neilmmm)
#### Post date: [June 3, 2008, 4:06pm UTC](https://forum.kirupa.com/t/randomly-generate-3-unique-numbers/262121/2 "2008-06-03T16:06:34Z")

</div>

i would do it by making an array of possible numbers, then selecting 3 of those numbers, but each time splicing out that number so it can’t be choosen again.

```auto
var temp_array:Array = new Array();
var choosenNumbers:Array = new Array();
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);

```

some people would make the temp array and shuffle function to shuffle the array and then just take the first 3 elements

---

<div class="post-metadata">

### Author: ![brostd](https://avatars.discourse-cdn.com/v4/letter/b/c6cbf5/32.png) [@brostd](https://forum.kirupa.com/u/brostd)
#### Post date: [June 3, 2008, 6:19pm UTC](https://forum.kirupa.com/t/randomly-generate-3-unique-numbers/262121/3 "2008-06-03T18:19:23Z")

</div>

Thank you very much that worked well. Now i am wondering what i would need to do to have that array reload with 3 new numbers after a 5 sec timer. Here is what i have now

```auto
myInterval = setInterval(doSomething, 5000) // 1000 represents 1 second
function doSomething(){
	choosenNumbers.splice(0,3);
	getImage();
}

```

This is the getImage function:

```auto
function getImage(){
		//create MC							  
	this.createEmptyMovieClip("vid10", this.getNextHighestDepth());
	vid10.createEmptyMovieClip("vid11", this.getNextHighestDepth());

	this.createEmptyMovieClip("vid20", this.getNextHighestDepth());
	vid20.createEmptyMovieClip("vid21", this.getNextHighestDepth());

	this.createEmptyMovieClip("vid30", this.getNextHighestDepth());
	vid30.createEmptyMovieClip("vid31", this.getNextHighestDepth());

//load images
	
	for (i=0; i<images.length; 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);

myInterval = setInterval(doSomething, 5000) // 1000 represents 1 second
function doSomething(){
	choosenNumbers.splice(0,3);
	getImage();
	}
	
	mcl.loadClip(images[temp_array[0]][1], "vid10.vid11");
	mcl.loadClip(images[temp_array[1]][1], "vid20.vid21");
	mcl.loadClip(images[temp_array[2]][1], "vid30.vid31");
		

	
	//pics location
	vid10._x = 38.5
	vid10._y = 57.5

	vid20._x = 179.5
	vid20._y = 57.5

	vid30._x = 320.5
	vid30._y = 57.5
	}

```
