### [Flashcoders] Determining probablity of a random pick.

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.

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.

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.

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.

An easy way is to if say you have 3 objects in a list given a weight options.weight = 1; options.weight = 3; options.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;

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

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