In fact you would not even have to extract the 10 numbers. Just generate a random starting_point between 0 and 89 and when you want a number
index using starting_point+i into the array of 100.

To generate your original array use the shuffle function from
http://www.sephiroth.it/proto_detail.php?id=149

You are going to get this done with almost no code.

Fill the array with 1 to 100,
Shuffle it
Set your shuffle counter to however many numbers you want to take before shuffling

Generate a starting point
set you number counter to 10
Take your next number array[starting point+i]
decrement your number counter
if your counter is not >0 pick a new starting_point and reset your number counter

decrement your shuffle counter on each number

if  your shuffle counter is not positive
shufffle and reset the shuffle counter.



Ron

laurent wrote:
That's a good idea!

Ron Wheeler a écrit :
If you do not care if the sequences repeat, you could fill an array with the numbers from 1 to 100 arranged in a random order.


When you want to grab 10, just pick a random integer between 0 and 89 and grab the block of 10 numbers following that point. This would charge a penalty once when you loaded the 100 but your refresh of the 10 would be very fast.

You could have a counter on the array of 100 and every so often (after 10-50 blocks of 10 used) regenerate the sequence of 100 if you want to avoid repeating the same sequence.

Ron


laurent wrote:

yes like:

allNumbers:Array = [ 0, 1, 2, 3, ..., 100 ];
tenNumbers:Array = [];

public function getNumberIn():void{
       var n:int = tenNumbers.splice( int( Math.random * 10 ), 1 );
tenNumbers.push( allNumbers.splice( int( Math.random * allNumbers.length ), 1 ) );
       allNumbers.push( n );
}

Could be like that. ;)
L


Eduardo Barbosa a écrit :
Hi Laurent,

Your first suggestion is a very simple and clever trick i'll definetely keep
in mind for future situations.

However for this second variation you mean that I:

1) pick the numbers out of array 1  and splice it
2) move those numbers into array 2
3) when the length of array 1 would be 10 i would start picking the numbers
out of array 2 and do the inverse.

Is this what you mean?



On Mon, Jul 28, 2008 at 11:01 PM, laurent <[EMAIL PROTECTED]> wrote:

still it can be done like that you always keep the number of numbers
between two arrays...
and swap numbers from one to another, that your sure to neve have twice the
same one
yeah...! :]
L

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


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 3257 (20080710) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com





_______________________________________________

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


__________ Information from ESET NOD32 Antivirus, version of virus signature database 3257 (20080710) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


__________ Information from ESET NOD32 Antivirus, version of virus signature database 3257 (20080710) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




_______________________________________________
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


__________ Information from ESET NOD32 Antivirus, version of virus signature database 3257 (20080710) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




_______________________________________________
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

Reply via email to