# Repeat random numbers problem

**URL:** <https://forum.kirupa.com/t/repeat-random-numbers-problem/58595>\
**Category:** flash\
**Created:** [July 23, 2004, 9:14pm UTC](https://forum.kirupa.com/t/repeat-random-numbers-problem/58595 "2004-07-23T21:14:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![meandmymachine](https://avatars.discourse-cdn.com/v4/letter/m/ecae2f/32.png) [@meandmymachine](https://forum.kirupa.com/u/meandmymachine)\
**Post date:** [July 23, 2004, 9:14pm UTC](https://forum.kirupa.com/t/repeat-random-numbers-problem/58595/1 "2004-07-23T21:14:07Z")

</div>

Is there any way of preventing repeat numbers in random number generation?

I’ve tried using the pop function and the delete function on elements in an array which are randomly selected, but can’t get the effect I want. I’ve even tried making two variable values equivalent to each other to try and constrict repetition –but no joy.

Can anyone give me any more ideas? Many thanks.

meandmymachine

---

<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 24, 2004, 1:13am UTC](https://forum.kirupa.com/t/repeat-random-numbers-problem/58595/2 "2004-07-24T01:13:50Z")

</div>

what are the parameters?

Just any random number?

A specific range?

if it’s a range, say 0 to 30, then use an array and this:

numarray = [0,1,2,3,4,5,6,7,8,9…etc…,30];  
loop here in whichever fashion suits you {  
randnum = Math.floor(Math.random()\*numarray.length);  
newnum = numarray.splice(randnum);  
}  
(I think)

if it’s a totally random number, I’m guessing you’re rounding it up, probably best to make an array, and run a compare through it, although that will start getting slow pretty quick, I guess.

Maybe someone else could help out if that’s the case.

---

<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 24, 2004, 5:48am UTC](https://forum.kirupa.com/t/repeat-random-numbers-problem/58595/3 "2004-07-24T05:48:42Z")

</div>

see if this helps [http://www.gifsrus.com/testfile/randNumb.fla](http://www.gifsrus.com/testfile/randNumb.fla)  
but like Dal`s solution is resticted to a range.

---

<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 25, 2004, 11:30am UTC](https://forum.kirupa.com/t/repeat-random-numbers-problem/58595/4 "2004-07-25T11:30:10Z")

</div>

Thanks for the link and the tip about the splice method. I’ll try that next.

meandmymachine
