[Flashcoders] Determining probablity of a random pick.

2009-06-22 Thread Jiri
Hello list, I have an XMLList that can vary in length. I pick a random node each time using the simple method below: code var tRandom:int = int(Math.random()*tXMLSource.nodes.length() ); return tXMLSource.nodes[tRandom] /code Now i would like to change it, so that I can specify a weight to

Re: [Flashcoders] Determining probablity of a random pick.

2009-06-22 Thread Paul Andrews
Jiri wrote: Hello list, I have an XMLList that can vary in length. I pick a random node each time using the simple method below: code var tRandom:int = int(Math.random()*tXMLSource.nodes.length() ); return tXMLSource.nodes[tRandom] /code Now i would like to change it, so that I can specify

Re: [Flashcoders] Determining probablity of a random pick.

2009-06-22 Thread Jiri
Thank you i understand it. Could u please elloborate on the last part ..You can optimise this by using an array of pointers.. Do you mean that this; a weight=5 b weight=1 c weight=2 First calculated the range for each node. A = 0 - 5 B = 6 - 7 C = 8 - 10 Then store in an array like so?

Re: [Flashcoders] Determining probablity of a random pick.

2009-06-22 Thread Paul Andrews
Jiri wrote: Thank you i understand it. Could u please elloborate on the last part ..You can optimise this by using an array of pointers.. Do you mean that this; a weight=5 b weight=1 c weight=2 First calculated the range for each node. A = 0 - 5 B = 6 - 7 C = 8 - 10 Then store in an array

Re: [Flashcoders] Determining probablity of a random pick.

2009-06-22 Thread Anthony Pace
An easy way is to if say you have 3 objects in a list given a weight options[0].weight = 1; options[1].weight = 3; options[2].weight = 4; instead of having it have three selections, you could add the weights and make it have 8 to choose from that point to the option. choice[0]=0;

Re: [Flashcoders] Determining probablity of a random pick.

2009-06-22 Thread Jiri
I see, that makes sense. Cheers. Jiri Paul Andrews wrote: Jiri wrote: Thank you i understand it. Could u please elloborate on the last part ..You can optimise this by using an array of pointers.. Do you mean that this; a weight=5 b weight=1 c weight=2 First calculated the range for each