From 98511d1b21764e8393a7b615cabcac506dc9abc7 Mon Sep 17 00:00:00 2001 From: IProduceWidgets <107586145+IProduceWidgets@users.noreply.github.com> Date: Sun, 20 Apr 2025 20:57:20 -0400 Subject: [PATCH] Binomial Number Selector for EntityTables (#36783) * binomial dist * lol initialize the int tho idiot * xml docs my forgotten * ditto --- .../ValueSelector/BinomialNumberSelector.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Content.Shared/EntityTable/ValueSelector/BinomialNumberSelector.cs diff --git a/Content.Shared/EntityTable/ValueSelector/BinomialNumberSelector.cs b/Content.Shared/EntityTable/ValueSelector/BinomialNumberSelector.cs new file mode 100644 index 0000000000..b3ed076e70 --- /dev/null +++ b/Content.Shared/EntityTable/ValueSelector/BinomialNumberSelector.cs @@ -0,0 +1,38 @@ +using Robust.Shared.Random; + +namespace Content.Shared.EntityTable.ValueSelector; + +/// +/// Picks a value based on a Binomial Distribution of N Trials given P Chance +/// +public sealed partial class BinomialNumberSelector : NumberSelector +{ + /// + /// How many times to try including an entry. i.e. the Max. + /// + [DataField] + public int Trials = 1; + + /// + /// The odds a single trial succeeds + /// + /// + /// my preferred "Prob" was already used in other places for entity table stuff and I didnt want more confusing terminology + /// + [DataField] + public float Chance = .5f; + + public override int Get(System.Random rand) + { + var random = IoCManager.Resolve(); + int count = 0; + + for (int i = 0; i < Trials; i++) + { + if (random.Prob(Chance)) + count++; + } + return count; + // get binomialed motherfucker + } +} -- 2.51.2