G1R AngelScript
Scripting reference for the Gothic 1 Remake
Loading...
Searching...
No Matches
WeightedRandomChoice Namespace Reference

Functions

Functions
int WeightedRandomIndex (TArray< float32 > Weights)
 Given an array of weights, returns a randomly chosen index where those with higher weights are more likely to be chosen.

Function Documentation

◆ WeightedRandomIndex()

int WeightedRandomIndex ( TArray< float32 > Weights)

Given an array of weights, returns a randomly chosen index where those with higher weights are more likely to be chosen.

To randomly choose an element of an array, make another array (of the same size) containing the weights of your elements. This function will then return a random index into that weight array. Since both arrays are of the same size, you can use that index on your original array.

Note: Weights cannot be negative!

Returns
Random index into the array of weights you passed. INDEX_NONE if the array was empty.