From cd4047084effe1e572b2da954c9cc6e7ffe4e79d Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Sat, 30 Jan 2021 16:20:45 +0000 Subject: Added unitest --- iada.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/iada.rb b/iada.rb index 598357e..f8dbba7 100755 --- a/iada.rb +++ b/iada.rb @@ -106,4 +106,20 @@ bot.command(:init, description: "Roll a d10 (1-10) and add an init modifier, wit res end +bot.command(:unitest, description: "Perform a uniformity test for peace of mind.") do |event| + t = 10_000_000 + u = t / 100 + + a = Array.new(100, 0) + t.times { a[rand(100)] += 1 } + + d2 = a.map { |o| (o - u) ** 2 } + s2 = d2.sum / 100.0 + s = s2 ** 0.5 + + res = "#{event.author.display_name} requested a uniformity test. #{t} dice were rolled and counted. The standard deviation was #{"%.2f" % s}, which means 68% of the possible outcomes each appeared within #{s.ceil} of the expected #{u} times, 95% within #{(s*2).ceil}, and 99.7% within #{(s*3).ceil}." + puts res + res +end + bot.run -- cgit v1.2.3