Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to use GamesDice to produce stats for fixed size dice pool
# Related to:
require 'games_dice'
die_types = [ 4, 6, 8, 10, 12, 20 ]
die_types.each_cons(2) do |type_lower, type_upper|
(0..6).each do |num_upper|
num_lower = 6 - num_upper
# We want 6d20, but we don't want repetition
next if num_upper == 6 && type_upper != 20
# Generate dice description. GamesDice does not treat e.g. "0d6" as valid.
# The "m4" is a way of coding: Score 0 by default, or 1 when result is 4 or higher
dice_text = case num_upper
when 0 then "#{num_lower}d#{type_lower}m4"
when 6 then "#{num_upper}d#{type_upper}m4"
else "#{num_lower}d#{type_lower}m4 + #{num_upper}d#{type_upper}m4"
# Creates a GamesDice::Dice object
dice_pool = GamesDice.create dice_text
# Output heading then probabilities
puts "\n#{dice_text.gsub(/m4/,'')}, target 4+"
probs = dice_pool.probabilities
(1..6).each do |successes|
print " #{successes}:#{sprintf('%5.1f', probs.p_ge(successes) * 100)}%"

This comment has been minimized.

Copy link
Owner Author

@neilslater neilslater commented May 7, 2014

I'm happy to answer questions about this script here, or on StackOverflow.


This comment has been minimized.

Copy link

@Mattadlard Mattadlard commented Jul 12, 2017

\Would this be an option for working out Probability of being able to purchase a card in my custom die system?

Question here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment