Fun with Python: A Terminal Dice Roller

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:

  1. It fetches the last two blocks from the Hive blockchain.
  2. It creates a unique seed string by combining the block_id of both blocks and the transaction_id of the first transaction in the most recent block.
  3. 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:

dice_1.png

It can also parse more complex dice notation, including multiple types of dice and modifiers, like 1d20+3-2d6+3:

dice_2.png

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

0.08284404 BEE
1 comments

If I ever need a dice roller of any sort, I know where to come! I'm curious, when do you use a dice roller in a terminal? 😁 πŸ™ πŸ’š ✨ πŸ€™

0.00020271 BEE

Whenever I'm working on an adventure, for things like rolling on an encounter table, or treasure / magic item tables. To figure out how many HP something has. Basically anytime I don't want to roll physical dice, and since I work on documents in NeoVim, 99% of the time, it's easier than stopping what I'm doing to open a browser and move the mouse around etc.

0.00000311 BEE

Ah, OK I see, and that makes sense! Thanks a lot for the explanation, my friend, I appreciate it! πŸ˜πŸ™πŸ’šβœ¨πŸ€™

0.00019864 BEE