Skip to content

AmnesicOblex/dice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dice

The @amnesic0blex/dice module is a collection of simple functions that help with random generation.

Usage

First make sure the package is installed

npm install @amnesic0blex/dice

Table of contents

Dice Roller

Simulates the rolling of an arbitrary number of arbitrary sided dice. In this example @amnesic0blex/dice simulates rolling 1d100 and 4d6. Also the dice.getSum is a reduction function that sums an array. This can be used to get the sum of multiple dice rolls.

const dice = require('@amnesic0blex/dice')
 
console.log(`1d100: ${dice.roll(1,100)}`)
var rolls = dice.roll(4,6)
console.log(`4d6: ${rolls}`)
console.log(`Sum 4d6: ${rolls.reduce(dice.getSum)}`)

Random Integer Generator

Generates a random integer between two values. If only one value is given it is assumed to be the maximum and the minimum is assumed to be 1.

const dice = require('@amnesic0blex/dice')

console.log(dice.randInt(1,10))
console.log(dice.randInt(10))
console.log(dice.randInt(0,10))
console.log(dice.randInt(-5,5))

Coin Flipper

Simulates the flipping of a double-sided coin. Returns boolean true or false.

const dice = require('@amnesic0blex/dice')
var heads = 0
var tails = 0
for (var i = 0; i < 100; ++i) {
    if (dice.flip()) {
        ++heads
    } else {
        ++tails
    }
}
console.log(`Heads: ${heads}`)
console.log(`Tails: ${tails}`)

Ability Score Modifiers

Calculates the 5e ability score modifier from an ability score.

const dice = require('@amnesic0blex/dice')

for (var i = 3; i < 20; ++i) {
    console.log(`Score: ${i}`)
    console.log(`Mod: ${dice.mod(i)}`)
    console.log()
}

Table

Randomly selects a value from a table, with each value weighted evenly.

const dice = require('@amnesic0blex/dice')
var classTable = [
    "Barbarian",
    "Bard",
    "Cleric",
    "Druid",
    "Fighter",
    "Monk",
    "Paladin",
    "Ranger",
    "Rogue",
    "Sorcerer",
    "Warlock",
    "Wizard"
]

console.log(dice.rollTable(classTable))

Weighted Table

Randomly selects a value from a table, with each value weighted individually.

const dice = require('@amnesic0blex/dice')
var raceTable = [
    {
        weight: 1,
        value: "Dragonborn"
    },
    {
        weight: 20,
        value: "Dwarf"
    },
    {
        weight: 15,
        value: "Elf"
    },
    {
        weight: 5,
        value: "Gnome"
    },
    {
        weight: 10,
        value: "Half-Elf"
    },
    {
        weight: 7,
        value: "Half-Orc"
    },
    {
        weight: 5,
        value: "Halfling"
    },
    {
        weight: 35,
        value: "Human"
    },
    {
        weight: 2,
        value: "Tiefling"
    }
]

console.log(dice.rollWeightedTable(raceTable))

About

Dice rolling node module for dnd.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published