Skip to content

Instantly share code, notes, and snippets.

@SHiLLySiT
SHiLLySiT / weightedChoice
Created March 27, 2012 23:55
Randomly chooses from a set of weighted objects (ints, strings, numbers, etc)
/**
* Randomly chooses from a set of weighted objects (ints, strings, numbers, etc)
* @param objs The objects to choose from.
* @param objWeights The weight of each respective object.
* @return The randomly chosen value.
*/
public static function weightedChoice(objs:Array, objWeights:Array):*
{
var weighedObjs:Array = new Array(); //new array to hold "weighted" obj
var currentObj:int = 0;