aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2021-01-30 16:20:45 +0000
committerNat Lasseter <user@4574.co.uk>2021-01-30 16:20:45 +0000
commitcd4047084effe1e572b2da954c9cc6e7ffe4e79d (patch)
treee29b7938800a98a1bf282ae3f25e582c1110fc10
parentc00b97ff1d736b4944ef297a54cc99fa008cbf9f (diff)
Added unitest
-rwxr-xr-xiada.rb16
1 files changed, 16 insertions, 0 deletions
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