Re: [Flashcoders] Random numbers list

2008-07-29 Thread Juan Pablo Califano
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:
>
> 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


RE: [Flashcoders] Random numbers list

2008-07-29 Thread Jesse Graupmann
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


Re: [Flashcoders] Random numbers list

2008-07-29 Thread Ron Wheeler
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

Re: [Flashcoders] Random numbers list

2008-07-29 Thread laurent

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


Re: [Flashcoders] Random numbers list

2008-07-29 Thread Helmut Granda
wrong thread... oh my and its only tuesday!

On Tue, Jul 29, 2008 at 9:57 AM, Helmut Granda <[EMAIL PROTECTED]>wrote:

> No, that is not the only way you can target a path in the MAC. for example
> I different projects some require to distribute the PPV classes with the
> project so i add the classes inside the same folder I am working on.
> /Application.as
> /src/
> /src/ppvclasses
>
> Then in my application I just do:
>
> import org.papervision3d.cameras.FreeCamera3D
>
> But if I am just testing it doesnt matter where the classes are as long as
> I target the class path properly.
>
> If you are still having issues I would recommend to read the following
> document:
>
>
> http://livedocs.adobe.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=1075.html
>
>
> On Tue, Jul 29, 2008 at 9:21 AM, Ron Wheeler <
> [EMAIL PROTECTED]> wrote:
>
>> 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.figle

Re: [Flashcoders] Random numbers list

2008-07-29 Thread Helmut Granda
No, that is not the only way you can target a path in the MAC. for example I
different projects some require to distribute the PPV classes with the
project so i add the classes inside the same folder I am working on.
/Application.as
/src/
/src/ppvclasses

Then in my application I just do:

import org.papervision3d.cameras.FreeCamera3D

But if I am just testing it doesnt matter where the classes are as long as I
target the class path properly.

If you are still having issues I would recommend to read the following
document:

http://livedocs.adobe.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=1075.html


On Tue, Jul 29, 2008 at 9:21 AM, Ron Wheeler <[EMAIL PROTECTED]
> wrote:

> 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
>>>
>>>
>>>
>>>
>> ___

RE: [Flashcoders] Random numbers list

2008-07-29 Thread Keith Reinfeld

> 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. ;)

Make a temporary copy of the allnumbers array then splice from the copy.

AS2: 


var allNumbers:Array = [0, 1, 2, 3, ..., 100];
var tenNumbers:Array = [38, 10, 70, 30, 63, 20, 66, 37, 16, 87];
function getNumberIn():Void{
var ca:Array = [].concat(allNumbers);
var n:Number = 10;
while(n--){
tenNumbers[n] = ca.splice(Math.floor(Math.random() *
ca.length - 1), 1);
}
trace("\ntenNumbers = "+tenNumbers);
}



Regards, 

-Keith 
http://keithreinfeld.home.comcast.net
 



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


Re: [Flashcoders] Random numbers list

2008-07-29 Thread Ron Wheeler
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


Re: [Flashcoders] Random numbers list

2008-07-28 Thread laurent


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


Re: [Flashcoders] Random numbers list

2008-07-28 Thread laurent
or perhaps tenNumber[ tenNumbers.length ] is faster than 
tenNumbers.push() never know about that one...the second return 
something so perhaps its slower..


laurent a écrit :


yes like:

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


public function getNumberIn():void{
   var i:in = int( Math.random * allNumber.length );
  tenNumbers.push( allNumber.splice( i, 1 ) );
}

then I don't know how you pick up the number to pass from tenNumbers 
to allNumber.


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


Re: [Flashcoders] Random numbers list

2008-07-28 Thread laurent


yes like:

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


public function getNumberIn():void{
   var i:in = int( Math.random * allNumber.length );
  tenNumbers.push( allNumber.splice( i, 1 ) );
}

then I don't know how you pick up the number to pass from tenNumbers to 
allNumber.


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


Re: [Flashcoders] Random numbers list

2008-07-28 Thread Eduardo Barbosa
Hi Steve,

That was actually my first thought. I had a while loop and inside a for ...
in loop to iterate through the array to check if the number was already
there. But then for some reason the script made flash unresponsive.

However  I just came up with this which seems to be working, but i'm still
very curious to learn of better ways of achieving this:

function pickUniqueNumber():Number {

var randomNum:Number;
var loop:Boolean = true;

var numberList:String = "|"+currentNumbers.join("|")+"|";

while (loop) {

randomNum = random(wallpaperList.length);

var numberString:String = "|"+randomNum+"|";

if (numberList.indexOf(numberString) == -1) {
currentNumbers.push(randomNum);
loop = false;
}
}
return randomNum;
}

On Mon, Jul 28, 2008 at 11:04 PM, Steve Abaffy <[EMAIL PROTECTED]>wrote:

> Every time you generate a new random number go through the array and see if
> any match the new number if so generate a new one and check again, if not
> add it to the array.
> With only 10 numbers in the array it would check very fast so you wouldn't
> be taking a performance hit.
>
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Eduardo
> Barbosa
> Sent: Monday, July 28, 2008 4:43 PM
> To: Flashcoders mailing list
> Subject: [Flashcoders] Random numbers list
>
> 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
>
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Random numbers list

2008-07-28 Thread Eduardo Barbosa
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


Re: [Flashcoders] Random numbers list

2008-07-28 Thread Eduardo Barbosa
Hi Matt,

Yes numbers can and should repeat through time. They just cant be repeated
within the sequence at a given discreet time. Makes sense? :)

On Mon, Jul 28, 2008 at 11:15 PM, Matt S. <[EMAIL PROTECTED]> wrote:

> Can numbers repeat? Is this a constant loop where, for instance, the
> number 12 could show up two times in twenty seconds? Or would you want
> 12 to show up once and then go out of circulation permanently?
>
> .m
>
> On Mon, Jul 28, 2008 at 5:42 PM, Eduardo Barbosa <[EMAIL PROTECTED]>
> wrote:
> > 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
>
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Random numbers list

2008-07-28 Thread Matt S.
Can numbers repeat? Is this a constant loop where, for instance, the
number 12 could show up two times in twenty seconds? Or would you want
12 to show up once and then go out of circulation permanently?

.m

On Mon, Jul 28, 2008 at 5:42 PM, Eduardo Barbosa <[EMAIL PROTECTED]> wrote:
> 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


RE: [Flashcoders] Random numbers list

2008-07-28 Thread Steve Abaffy
Every time you generate a new random number go through the array and see if
any match the new number if so generate a new one and check again, if not
add it to the array.
With only 10 numbers in the array it would check very fast so you wouldn't
be taking a performance hit. 


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Eduardo
Barbosa
Sent: Monday, July 28, 2008 4:43 PM
To: Flashcoders mailing list
Subject: [Flashcoders] Random numbers list

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


Re: [Flashcoders] Random numbers list

2008-07-28 Thread laurent
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


Re: [Flashcoders] Random numbers list

2008-07-28 Thread laurent

oops no i did not get you point actually..
hm...more complex...:)
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


Re: [Flashcoders] Random numbers list

2008-07-28 Thread laurent
you could make a first array filled with all number from 0 to 100 and 
then you splice to any random index range between 0 and the new size of 
the array.

You fill another array with the last spliced number. do I make sense ?
cheers
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] Random numbers list

2008-07-28 Thread Eduardo Barbosa
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


Re: [Flashcoders] Random numbers?

2006-07-23 Thread Charles Parcell

It is the difference between floor and round.

Charles P.


On 7/23/06, Rajat Paharia <[EMAIL PROTECTED]> wrote:


Can someone help me understand why the randRange function below doesn't
return a random distribution, but the randRange2 function does?
Here's some test code.

thanks, - rajat


var a = [0,0,0,0,0];
var b = [0,0,0,0,0];
var x;

for (var i=0; i < 1000; i++) {
x = randRange(1,4);
a[x]++;
x = randRange2(1,4);
b[x]++;

}

trace ("a: " + a);
trace ("b: " + b);


// --
// Generate a random number in a range.
function randRange(min, max) {
  var randomNum = Math.round(Math.random()*(max-min))+min;
  return randomNum;
}

// Generate a random number in a range.
function randRange2(min, max) {
  var randomNum = min + Math.floor(Math.random() * (max + 1 - min));
  return randomNum;
}

--
Rajat Paharia
[EMAIL PROTECTED]
http://www.bunchball.com
http://www.rootburn.com
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


[Flashcoders] Random numbers?

2006-07-23 Thread Rajat Paharia

Can someone help me understand why the randRange function below doesn't
return a random distribution, but the randRange2 function does?
Here's some test code.

thanks, - rajat


var a = [0,0,0,0,0];
var b = [0,0,0,0,0];
var x;

for (var i=0; i < 1000; i++) {
   x = randRange(1,4);
   a[x]++;
   x = randRange2(1,4);
   b[x]++;

}

trace ("a: " + a);
trace ("b: " + b);


// --
// Generate a random number in a range.
function randRange(min, max) {
 var randomNum = Math.round(Math.random()*(max-min))+min;
 return randomNum;
}

// Generate a random number in a range.
function randRange2(min, max) {
 var randomNum = min + Math.floor(Math.random() * (max + 1 - min));
 return randomNum;
}

--
Rajat Paharia
[EMAIL PROTECTED]
http://www.bunchball.com
http://www.rootburn.com
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com