Example #1
0
    public static T SelectRandom(T[] from)
    {
        float total = WeightedSet <T> .GetTotalWeight(from);

        int index = WeightedSet <T> .SelectRandomIndex(from, total);

        if (index == -1)
        {
            return(default(T));
        }
        return(from[index]);
    }
Example #2
0
    public static int SelectRandomIndex(T[] from)
    {
        float total = WeightedSet <T> .GetTotalWeight(from);

        return(WeightedSet <T> .SelectRandomIndex(from, total));
    }