diff options
author | Nat Lasseter <user@4574.co.uk> | 2021-01-30 16:20:45 +0000 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2021-01-30 16:20:45 +0000 |
commit | cd4047084effe1e572b2da954c9cc6e7ffe4e79d (patch) | |
tree | e29b7938800a98a1bf282ae3f25e582c1110fc10 | |
parent | c00b97ff1d736b4944ef297a54cc99fa008cbf9f (diff) |
Added unitest
-rwxr-xr-x | iada.rb | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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 |