# Dissplay 6 numbers random but once only

**URL:** <https://forum.kirupa.com/t/dissplay-6-numbers-random-but-once-only/116949>\
**Category:** Uncategorized\
**Created:** [July 22, 2004, 7:01pm UTC](https://forum.kirupa.com/t/dissplay-6-numbers-random-but-once-only/116949 "2004-07-22T19:01:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emorej](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@emorej](https://forum.kirupa.com/u/emorej)\
**Post date:** [July 22, 2004, 7:01pm UTC](https://forum.kirupa.com/t/dissplay-6-numbers-random-but-once-only/116949/1 "2004-07-22T19:01:31Z")

</div>

[font=Arial]Im trying to display 6 numbers with actionscript, 1 to 6 but in random order and only used once.[/font]

[font=Arial]I tried Random function but that returns same numbers twice or more.[/font]

[font=Arial] [/font]

[font=Arial] [/font]

[font=Arial]This is the code I used [/font]

[font=Arial] [/font]

[font=Arial] [/font]

[font=Arial] [/font]

[font=Arial] [/font]

[font=Arial] Math.randomBetween = function(a,b) {[/font]

[font=Arial] return (a + Math.floor(Math.random()\*(b-a+1)));[/font]

[font=Arial] }[/font]

[font=Arial] [/font]

[font=Arial] [/font]

[font=Arial] for (var i = 4; i \< 9; i++) {[/font]

[font=Arial] spread = Math.randomBetween(4, 8);[/font]

[font=Arial] [/font]

[font=Arial] [/font]

[font=Arial]Can anyone help[/font]

thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 22, 2004, 7:40pm UTC](https://forum.kirupa.com/t/dissplay-6-numbers-random-but-once-only/116949/2 "2004-07-22T19:40:48Z")

</div>

> [@emorej](#):
>
> [font=Arial]Im trying to display 6 numbers with actionscript, 1 to 6 but in random order and only used once.[/font]
> 
> [font=Arial]I tried Random function but that returns same numbers twice or more.[/font]
> 
> [font=Arial] [/font]
> 
> [font=Arial] [/font]
> 
> [font=Arial]This is the code I used [/font]
> 
> [font=Arial] [/font]
> 
> [font=Arial] [/font]
> 
> [font=Arial] [/font]
> 
> [font=Arial] [/font]
> 
> [font=Arial] Math.randomBetween = function(a,b) {[/font]
> 
> [font=Arial] return (a + Math.floor(Math.random()\*(b-a+1)));[/font]
> 
> [font=Arial] }[/font]
> 
> [font=Arial] [/font]
> 
> [font=Arial] [/font]
> 
> [font=Arial] for (var i = 4; i \< 9; i++) {[/font]
> 
> [font=Arial] spread = Math.randomBetween(4, 8);[/font]
> 
> [font=Arial] [/font]
> 
> [font=Arial] [/font]
> 
> [font=Arial]Can anyone help[/font]
> 
> thanks

Have a look at this, its very similar to what you are trying to do [http://www.gifsrus.com/testfile/randNumb.fla](http://www.gifsrus.com/testfile/randNumb.fla)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 3:03am UTC](https://forum.kirupa.com/t/dissplay-6-numbers-random-but-once-only/116949/3 "2004-07-23T03:03:49Z")

</div>

You mean like this? (albeit a somewhat half-arsed way to do it, but whatever, i’m tired… hehe… and haven’t played with AS in a long time)

```auto
//prototype function to randomize the array
Array.prototype.randomize = function() {
	var arrayLength = this.length;
	var randNum, tempArray;
	for (i=0; i<arrayLength; i++) {
		randNum = Math.floor(Math.random()*arrayLength);
		tempArray = this*;
		this* = this[randNum];
		this[randNum] = tempArray;
	}
};
//array containing the digits you want displayed in random order
myArray = ["1", "2", "3", "4", "5", "6"];
//call this whenever you want to re-arrange the order of numbers
myArray.randomize();
//use myArray.join("") to display the array as a string of number values
trace(myArray.join(""));

```
