Hey everyone,
Today I want to share a script for deterministic dice rolls right from the command line. If you know anything about me, you know I live in the terminal. Even though I built the ultimate-dice web app, sometimes I just want to roll some funky click-clack math rocks without leaving my shell. So, I built this.
Deterministic Dice Rolls in the Terminal
This script is a bit different from my web-based dice roller. It uses a method inspired by the old dice.js
smart contract from Hive-Engine, seeding its rolls using live data directly from the Hive blockchain to ensure a deterministic and provably fair result.
Here’s how it works:
- It fetches the last two blocks from the Hive blockchain.
- It creates a unique seed string by combining the
block_id
of both blocks and thetransaction_id
of the first transaction in the most recent block. - This seed is then hashed to generate a number that powers the random number generator, ensuring the roll is tied to that exact moment on the blockchain.
The script can handle simple rolls, like a standard 1d20
:
It can also parse more complex dice notation, including multiple types of dice and modifiers, like 1d20+3-2d6+3
:
It's a fun little tool for anyone who loves the command line and wants a quick way to get a provably fair dice roll for a TTRPG or any other reason.
You can find the script and run it directly from the Gist below.
As always,
Michael Garcia a.k.a. TheCrazyGM