Add early exit to GetWeightedValue

This commit is contained in:
Chomp
2025-02-26 11:41:39 +00:00
parent cff882c971
commit a000714f41
@@ -16,6 +16,11 @@ public class WeightedRandomHelper(
/// <returns>Chosen item from array</returns>
public T GetWeightedValue<T>(Dictionary<T, double> values) where T : notnull
{
if (values.Count == 1)
{
return values.Keys.First();
}
var itemKeys = values.Keys.ToList();
var weights = values.Values.ToList();