From 593dbec14db8450e612b5c4432f6be930ba25e29 Mon Sep 17 00:00:00 2001 From: anonym Date: Tue, 26 Nov 2024 13:18:26 +0100 Subject: [PATCH] Electrum wrapper: fix probability mistake Since random.random() picks a float between (inclusive on both ends) 0 and 1.0, `int(round(100 * random.random()))` picks an integer from 0 to 100, so 101 different outcomes, while we want 100. That 0 outcome skews unfairly toward the first listed CampaignOption (with non-zero probibility). --- config/chroot_local-includes/usr/local/bin/electrum | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/chroot_local-includes/usr/local/bin/electrum b/config/chroot_local-includes/usr/local/bin/electrum index ac5e11e017c..b5b88788123 100755 --- a/config/chroot_local-includes/usr/local/bin/electrum +++ b/config/chroot_local-includes/usr/local/bin/electrum @@ -56,8 +56,7 @@ class CampaignOptions: raise ValueError("probabilities must sum to 100") def choose(self) -> CampaignOption: - rand = random.random() # noqa: S311 - num = int(round(100 * rand)) + num = random.randint(1, 100) for opt in self.options: num -= opt.probability if num <= 0: -- 2.11.4.GIT