Select a single index in an array at random with different weights. Indices with negative weights are ignored. If all weights are <=0, this will return -1.
The weights for each item
The 0-based index of the randomly selected item
const index = SMath.selectRandomWeighted([3.5, 4, 1]); // 1 Copy
const index = SMath.selectRandomWeighted([3.5, 4, 1]); // 1
Select a single index in an array at random with different weights. Indices with negative weights are ignored. If all weights are <=0, this will return -1.