It's a dice roller, used for generating rolls that you might use in popular Tabletop Role-playing Games.
// Let's Roll!
import { roll } from 'randsum'
// Roll a single D20
roll(20)
// Roll 4 D20
roll({ quantity: 4, sides: 20 })
// Roll 4 D6, drop the lowest
roll({ quantity: 4, sides: 6, modifiers: { drop: { lowest: true } } })
// Do the same, but with dice notation
roll('4d6L')
// Roll 4 Fudge dice
roll({ quantity: 4, sides: ['+', '+', '-', '-', ' ', ' '] })
// Roll a single D20
import { D20 } from 'randsum'
D20.roll()
// Make a new 120 sided die and roll it
import { D } from 'randsum'
const D120 = new D(120)
D120.roll()
//'heads' or 'tails'?
const Coin = new D(['heads', 'tails'])
Coin.roll()
Written in 100% Typescript with strong attention paid to return types. You depend on randsum
to give you what you expect - just not always the roll you want.
Getting Started - Installation and Documentation for using randsum
Roll Dice Notation - A guide for using Dice Notation with randsum
.
Contributing - help make randsum
better!
Sophie's Dice Notation - a great dice notation guide that helped me along the way
_why's poignant guide to ruby - _why not?
Sometime around 2012, I decided I wanted to learn to program. I had installed ruby on the best laptop six-hundred dollars could buy, set to make a dice roller as an easy first project.
I spent an easy 30 minutes trying to figure out how to make rand(n)
return 1...n
instead of 0...(n-1)
.
When I found the answer, I laughed and laughed. I've been chasing that high ever since.