This is very similar to what other people have already said. Basically, you can have two lists: one acts as a pool from where you'll grab numbers, randomly; the other one is a sequence of unique numbers.
First, you fill the pool with numbers that fall between some range. Then you take one of the numbers in the pool and put it in the sequence list, untill you've filled it up. To "refresh" the sequence, just pick a random index from it, replace the value pointed by that index with a random value taken from the pool and put the value extracted from the sequence back into the pool. In code: import flash.utils.Timer; import flash.events.TimerEvent; var uniqueSequence:Array = []; var numbersPool:Array = []; var maxRange:int = 100; var minRange:int = 0; var sequenceSize:int = 10; function init():void { var i:int = minRange; while(i<maxRange) { numbersPool.push(i); i++; } i = 0; while(i<sequenceSize) { uniqueSequence.push(getFromPool()); i++; } } function getFromPool():int { var idx:int = Math.round((numbersPool.length - 1 )* Math.random()); return numbersPool.splice(idx,1)[0]; } function refresh():void { var seqIdx:int = Math.round((sequenceSize - 1 )* Math.random()); var tmp:int = uniqueSequence[seqIdx]; uniqueSequence[seqIdx] = getFromPool(); numbersPool.push(tmp); trace(uniqueSequence); } function handleTimer(evt:TimerEvent):void { refresh(); } init(); var timer:Timer = new Timer(250,50000); timer.addEventListener(TimerEvent.TIMER, handleTimer); timer.start(); Cheers Juan Pablo Califano 2008/7/29, Jesse Graupmann <[EMAIL PROTECTED]>: > > I'm sure this isn't needed by now, just thought I'd take it as a fun > challenge. > > > var rangeMin:int = 0; > var rangeMax:int = 100; > var rangeSample:int = 10; > > > // copy > var numbers:Array = []; > > // original values > var numberList:Array = []; > for ( var i:int = 0; i <= (rangeMax - rangeMin); i++ ) numberList[ i ] = > rangeMin + i; > > > function getRandomArray( len:int ):Array > { > // reset copy when needed > if ( numbers.length < len ) numbers = [].concat(numberList); > > // transfer random values to new array > var array:Array = []; > for ( var i:int = 0; i < len; i++ ) array [ i ] = numbers.splice( > int( Math.random() * numbers.length), 1 ); > > return array; > } > > > > for ( i = 0; i < 20; i++ ) trace( i + ": " + getRandomArray( rangeSample ) > ); > > > > >>>>>> > >>>>>> Eduardo Barbosa a écrit : > >>>>>> > >>>>>> > >>>>>>> Hi all! > >>>>>>> > >>>>>>> > >>>>>>> What I am trying to figure out is this: > >>>>>>> > >>>>>>> How to generate a sequence of random numbers where the newest is > >>>>>>> always > >>>>>>> different from all the previous? > >>>>>>> > >>>>>>> I need to continuosly rewrite an array of 10 random numbers in > >>>>>>> such a way > >>>>>>> that at any given time they are all different. > >>>>>>> > >>>>>>> Let's say that my range is 0 to 100 > >>>>>>> > >>>>>>> it starts with random numbers, all different: > >>>>>>> > >>>>>>> {3, 34, 12, 69, 6, 44, 31, 90, 88, 23} > >>>>>>> > >>>>>>> at a set interval some values are replaced by new ones so there > >>>>>>> are never > >>>>>>> two equal numbers, so, after 2 seconds it may look like this: > >>>>>>> > >>>>>>> {3, 66, 12, 79, 6, 44, 10, 81, 88, 23} > >>>>>>> > >>>>>>> > >>>>>>> Any ideas? > >>>>>>> > >>>>>>> Thanks :) > >>>>>>> Eduardo > > > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders