npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@amnesic0blex/dice

v1.0.6

Published

Dice rolling node module for dnd.

Downloads

6

Readme

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))