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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mcptoolshop/roll

v2.0.0

Published

RPG dice engine — expression parser, probability analyzer, loot tables, beautiful terminal output

Downloads

44

Readme

npx @mcptoolshop/roll 4d6dl1 --analyze
  Distribution

   3    0.08%
   4 █   0.31%
   5 ███   0.77%
   6 ███████   1.62%
   7 █████████████   2.93%
   8 ██████████████████████   4.78%
   9 ████████████████████████████████   7.02%
  10 ███████████████████████████████████████████   9.41%
  11 ████████████████████████████████████████████████████  11.42%
  12 ██████████████████████████████████████████████████████████  12.89%
  13 ████████████████████████████████████████████████████████████  13.27%
  14 ████████████████████████████████████████████████████████  12.35%
  15 ██████████████████████████████████████████████  10.11%
  16 █████████████████████████████████   7.25%
  17 ███████████████████   4.17%
  18 ███████   1.62%

┌─ Statistics ─────────────────────────────────┐
│ Mean:    12.24                                │
│ Median:  12                                   │
│ Mode:    13                                   │
│ Std Dev: 2.85                                 │
│ Range:   3–18                                 │
│ Entropy: 3.53 bits                            │
│                                               │
│ Percentiles:                                  │
│   p10:8  p25:10  p50:12  p75:14  p90:16  p95:17│
└───────────────────────────────────────────────┘

安装

npm install @mcptoolshop/roll

需要 Node.js >= 22。

命令行用法

投骰子

roll 2d6+3
roll d20+5
roll 4d6kh3
roll 1d6!
roll d%
roll 4dF
roll "(2d6+3)*2"

分析概率

roll 2d6 --analyze          # Full distribution + statistics
roll d20+5 --at-least 15    # P(result >= 15)

比较分布

roll --compare "4d6dl1" "3d6"

并排显示统计数据(均值、中位数、众数、标准差、范围、熵),包含差异列,以及直方图。

掉落表

roll --loot treasure.json

JSON 格式:

{
  "tables": [
    {
      "table": "Treasure",
      "items": [
        { "name": "Gold", "weight": 40, "roll": "2d6*10" },
        { "name": "Potion of Healing", "weight": 30 },
        { "name": "Scroll", "weight": 15, "quantity": "1d3" },
        { "name": "Rare Item", "weight": 5, "table": "Rare Weapons" }
      ]
    },
    {
      "table": "Rare Weapons",
      "items": [
        { "name": "Vorpal Blade", "weight": 5 },
        { "name": "Frost Brand", "weight": 25 }
      ]
    }
  ]
}

特性:加权选择、嵌套表引用、用于数量和值的骰子表达式。

其他选项

roll 2d6+3 --times 5       # Roll 5 times
roll 2d6+3 --json           # Machine-readable output
roll --help                 # Full usage
roll --version              # Version

骰子表示法

| 表示法 | 含义 | |----------|---------| | 2d6 | 投掷 2 个六面骰子 | | d20 | 投掷 1 个二十面骰子 | | 4d6kh3 | 投掷 4d6,保留最高的 3 个 | | 4d6dl1 | 投掷 4d6,舍弃最低的 1 个 | | 1d6! | 爆炸骰子(最大值时重新投掷,并加总) | | 1d6!>4 | 当结果为 4 或更高时爆炸 | | d% | 百分位骰子(1-100) | | 4dF | 命运/模糊骰子(-1、0、+1 各一个) | | (2d6+3)*2 | 带有分组的算术运算 | | 2d6+1d4+3 | 链式表达式 |

库 API

import { roll, analyze, parse, evaluate, computeDistribution } from '@mcptoolshop/roll';

// Quick roll
const result = roll('4d6kh3');
console.log(result.total);        // 14
console.log(result.groups[0].dice); // per-die breakdown

// Full analysis
const analysis = analyze('2d6+3');
console.log(analysis.stats.mean);                  // 10
console.log(analysis.stats.percentiles[95]);        // 14
console.log(analysis.probabilityAtLeast(12));       // 0.2778

// Low-level: parse → AST → evaluate
import { seededRng } from '@mcptoolshop/roll';
const ast = parse('4d6dl1');
const r = evaluate(ast, seededRng(42));  // deterministic

// Loot tables
import { rollLootTable } from '@mcptoolshop/roll';
const tables = [{ table: "Loot", items: [{ name: "Gold", weight: 50, roll: "2d6*10" }] }];
const drops = rollLootTable(tables);

概率引擎

  • 精确分布:通过多项式卷积计算基本 NdM 概率。
  • 完整枚举:用于保留/舍弃机制(4d6 = 1296 种状态)。
  • 截断递归:用于爆炸骰子(最多 10 次爆炸)。
  • 蒙特卡洛方法(10 万个样本):当精确计算超过 1000 万种状态时使用。

无外部依赖

完全基于 Node.js 22+ 的内置模块:

  • util.styleText 用于终端颜色。
  • util.parseArgs 用于命令行参数解析。
  • crypto.randomInt 用于密码学安全的骰子投掷。

安全与信任

@mcptoolshop/roll 只处理骰子表达式,不做其他任何操作。它不进行任何网络请求,不写入任何文件,也不收集任何数据。唯一的系统文件访问是 --loot 选项,它读取单个用户指定的 JSON 文件。

没有遥测数据,没有分析,也没有任何形式的跟踪。没有涉及任何秘密、令牌或凭据。

所有骰子投掷都使用 Node.js crypto 模块中的 crypto.randomInt,提供密码学安全的随机数,适用于公平的结果。

请参阅 SECURITY.md 以获取漏洞报告政策。

许可证

MIT


MCP Tool Shop 构建。