| Package | org.flintparticles.common.utils |
| Class | public class FastWeightedArray |
The FastWeightedArray is a collection of values that are weighted. When a random value is required from the collection, the value returned is randomly selkected based on the weightings.
Due to the nature of a FastWeightedArray, there are no facilities to push, unshift or splice items into the array. All items are added to the FastWeightedArray using the add method.
| Property | Defined by | ||
|---|---|---|---|
| length : uint [read-only]
The number of items in the FastWeightedArray
| FastWeightedArray | ||
| totalRatios : Number [read-only]
The sum of the weights of all the values.
| FastWeightedArray | ||
| Method | Defined by | ||
|---|---|---|---|
|
Then constructor function is used to create a FastWeightedArray
| FastWeightedArray | ||
|
add(value:*, ratio:Number):uint
Adds a value to the FastWeightedArray.
| FastWeightedArray | ||
|
clear():void
Empties the FastWeightedArray.
| FastWeightedArray | ||
|
getRandomValue():*
Returns a random value from the FastWeightedArray.
| FastWeightedArray | ||
| length | property |
length:uint [read-only]The number of items in the FastWeightedArray
Implementation public function get length():uint
| totalRatios | property |
totalRatios:Number [read-only]The sum of the weights of all the values.
Implementation public function get totalRatios():Number
| FastWeightedArray | () | constructor |
public function FastWeightedArray()Then constructor function is used to create a FastWeightedArray
| add | () | method |
public function add(value:*, ratio:Number):uintAdds a value to the FastWeightedArray.
Parametersvalue:* — the value to add
|
|
ratio:Number — the weighting to place on the item
|
uint — the length of the FastWeightedArray
|
| clear | () | method |
public function clear():voidEmpties the FastWeightedArray. After calling this method the FastWeightedArray contains no items.
| getRandomValue | () | method |
public function getRandomValue():*Returns a random value from the FastWeightedArray. The weighting of the values is used when selcting the random value, so items with a higher weighting are more likely to be seleted.
Returns* — A randomly selected item from the array.
|