From e09484cbe7b441acf73c68571615373c8d0703c6 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 26 Apr 2023 21:49:43 +0200 Subject: [PATCH] Fixed GetRandomWeightedEntry distribution not being equal for equal weights --- CHANGELOG.md | 1 + MLEM/Extensions/RandomExtensions.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b681821..5895b8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Fixes - Fixed TextInputs behaving incorrectly when switching between multiline and single-line modes - Fixed TextInput drawing characters with the wrong width if a masking character is used - Fixed a multiline TextInput's cursor not returning to the default position when the last character is removed +- Fixed GetRandomWeightedEntry distribution not being equal for equal weights Removals - Marked GetDownTime, GetUpTime and GetTimeSincePress in Keybind and Combination as obsolete diff --git a/MLEM/Extensions/RandomExtensions.cs b/MLEM/Extensions/RandomExtensions.cs index 0a5871d..250e50c 100644 --- a/MLEM/Extensions/RandomExtensions.cs +++ b/MLEM/Extensions/RandomExtensions.cs @@ -36,7 +36,7 @@ namespace MLEM.Extensions { var currWeight = 0; foreach (var entry in entries) { currWeight += weightFunc(entry); - if (currWeight >= goalWeight) + if (currWeight > goalWeight) return entry; } throw new IndexOutOfRangeException(); @@ -49,7 +49,7 @@ namespace MLEM.Extensions { var currWeight = 0F; foreach (var entry in entries) { currWeight += weightFunc(entry); - if (currWeight >= goalWeight) + if (currWeight > goalWeight) return entry; } throw new IndexOutOfRangeException();