Balatro's mind-bending code uses mouse jitter for random number generation, along with a bunch of clever maths I'm too dense to fully appreciate
Balatro, a roguelike deckbuilder, uses an innovative method of random number generation by leveraging mouse sensor jitter as a source of hardware entropy. The game captures mouse movement data and hover time when the 'new game' button is clicked to seed its RNG. Despite some messy code structures, the game's underlying math and programming techniques reveal clever optimizations. A YouTube deep dive highlights both the game's elegant solutions and its questionable coding practices.
- ▪Balatro uses mouse jitter—X/Y coordinates and hover duration—as entropy for its random number generation.
- ▪The RNG seed is set using hardware input collected when the player clicks the 'new game' button.
- ▪The game's code includes a 1,800-line if-else chain, reflecting some inefficient programming practices.
- ▪Despite 'bad' code appearances, the game employs sophisticated math tricks, such as floating-point encoding for card sorting.
- ▪The solo developer is praised for mathematical ingenuity, particularly in optimizing limited computational resources.
Opening excerpt (first ~120 words) tap to expand
Software Balatro's mind-bending code uses mouse jitter for random number generation, along with a bunch of clever maths I'm too dense to fully appreciate News By Andy Edser published 28 April 2026 Bear with me, I'm going out on a limb here. When you purchase through links on our site, we may earn an affiliate commission. Here’s how it works. Copy link Facebook X Whatsapp Reddit Pinterest Flipboard Email Share this article 0 Join the conversation Follow us Add us as a preferred source on Google Newsletter Subscribe to our newsletter Balatro Source Code Review: "Bad" Code & Math Tricks - YouTube Watch On Let me start off this article with a caveat: I am not a coding expert. I'm also not particularly good at maths.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at PCGamer latest .