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;
choice[1]=1;
choice[2]=1;
choice[3]=1;
choice[4]=2;
choice[5]=2;
choice[6]=2;
choice[7]=2;


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 a weight to each node. This weight would have to determine the probability the nodes get selected out when a random pick is being performed.

Does anybody know how to build such an algorithm?

Much appreciated,

Jiri
_______________________________________________
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