aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xiada.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/iada.rb b/iada.rb
index 409da57..6bfa417 100755
--- a/iada.rb
+++ b/iada.rb
@@ -2,6 +2,10 @@
require 'discordrb'
+def make_roll(dX = 100)
+ rand(100_000_000 * dX) % dX
+end
+
def human_result(name, roll, vs, fr, prefix = "")
case roll
when 0
@@ -39,7 +43,7 @@ bot = Discordrb::Commands::CommandBot.new token: ENV['DISCORD_TOKEN'], client_id
bot.command(:vs, description: "Roll a d100 (0-99) against a target number, with optional comment.") do |event, vs, *fr|
vs = vs.to_i
- roll = rand(100)
+ roll = make_roll
last_roll[event.author.id] = [roll, vs, fr]
@@ -54,7 +58,7 @@ bot.command(:again, description: "Repeat your last vs roll.") do |event|
if roll.nil?
res = "You need to roll something first, #{event.author.display_name}!"
else
- roll = rand(100)
+ roll = make_roll
last_roll[event.author.id] = [roll, vs, fr]
res = human_result(event.author.display_name, roll, vs, fr, "Repeat: ")
@@ -95,11 +99,11 @@ end
bot.command(:init, description: "Roll a d10 (1-10) and add an init modifier, with two tie-break d10 (0-9) rolloffs.") do |event, mod|
mod = mod.to_i
- roll = rand(10) + 1
+ roll = make_roll(10) + 1
tot = roll + mod
- d1 = rand(10)
- d2 = rand(10)
+ d1 = make_roll(10)
+ d2 = make_roll(10)
res = "#{event.author.display_name} rolled `#{roll}` and scored `#{tot}.#{d1}#{d2}` for initiative."
puts res
@@ -111,13 +115,13 @@ bot.command(:unitest, description: "Perform a uniformity test for peace of mind.
u = t / 100
a = Array.new(100, 0)
- t.times { a[rand(100)] += 1 }
+ t.times { a[make_roll] += 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}."
+ res = "#{event.author.display_name} requested a uniformity test. #{t} d100s 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