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
๐Ÿ–ฅ PCNews
#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

PC Gamer RSS Feedโœ Andy Edserโฑ 3 min read(5 months ago)

Overview & Key Takeaways

Bear with me, I'm going out on a limb here.

Balatro Source Code Review: "Bad" Code & Math Tricks - YouTube Balatro Source Code Review:

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. Which means some of the explanations in the video above fly over the top of my head at considerable speed.

One thing I do understand, however, is that the code that makes up roguelike deckbuilder Balatro is very clever. YouTube channel Howdy has reverse-engineered the game's source code to pull out some of its more bizarre nuancesโ€”and if you're more mathematically minded than me, you might even understand half of it.

One key takeaway that does make sense, though, is the way it uses mouse sensor jitter as 'cheap hardware entropy for RNG'. It's an impressive bit of lateral thinking, as the game takes hardware input data and puts it to work for random number generating purposes.

The 'jitter data', which is essentially the X and Y co-ordinates of your mouse combined with the hover duration, is collected when you click the new game button and used to set the values of the game seed. How cool is that?

The popular opinion around Balatro's code is described by Howdy as "kinda horrible", but the deep dive reveals that the game is actually full of clever maths tricks. And, it must be said, the odd section with some bad practices.

(Image credit: LocalThunk)

There's a gigantic if-else chain inside one of the .lua files, for example, with 190+ branches that are used to set data for various in-game abilities. Another chain is made up of 1,800 lines of code, which seems closer to my style of writing.

Ask my editors, bless 'em. It's not just coders who have a tendency to spew out vast amounts of unnecessarily dense text.

Keep up to date with the most important stories and the best deals, as picked by the PC Gamer team.

All that being said, Howdy seems very impressed with Balatro's lone dev. The channel points out that features like the floating-point solution for card sorting, which puts multiple different variables into a single float value with specific decimal lanes, are indicative of a coder Howdy describes as "hella good at maths."

Which I am not. If you are, though, you'll probably get more out of this than me. I'm a hardware writer who spends his life knee-deep in cables and chip architecture diagrams, and the nuts and bolts of software coding can leave me cold. Balatro very good, very clever card game, though. I do get that.

Best PC build 2026

Share:

More in PC

The Witcher 3 'is not untouchable,' story director says of changes in the upcoming remaster: 'I still find some places that I think maybe nowadays, I would do it differently'๐Ÿ–ฅ PC

The Witcher 3 'is not untouchable,' story director says of changes in the upcoming remaster: 'I still find some places that I think maybe nowadays, I would do it differently'

CD Projekt aims to make The Witcher 3 remaster feel like a 2026 game, and that means bigger changes than you might expect.

๐ŸŽฎ The Witcher 3
PCNewsabout 3 hours ago
Mortal Shell 2: Castigator's Keep walkthrough (Part 22)๐Ÿ–ฅ PlayStation, Xbox, PC

Mortal Shell 2: Castigator's Keep walkthrough (Part 22)

!(https://assetsio.gnwcdn.com/mortal-shell-2-egon-in-castigators-keep.jpg?width=690&quality=85&format=jpg&auto=webp) Continuing straight on from the previous part of our walkthrough of Mortal Shell 2(https://www.rockpapershotgun.com/games/mortal-shell-2), the path ahead is quite clear: you must now journey southeast from the Lonesome Spire, dipping into the Vestige Of Infinity before descending into the expansive Castigator's Keep. Castigator's Keep is home to a fair few dungeons, some of them quite large; and you'll also need to fight through several bosses and a great many lesser foes to explore it all. On the bright side, you'll also obtain a new Sidearm - the Triarch Repeater. Follow along with the steps below for our full 100% walkthrough of Castigator's Keep! Read more(https://www.rockpapershotgun.com/mortal-shell-2-walkthrough-part-22-castigators-keep)

RockGuides / Walkthroughsabout 4 hours ago
If you need proof The Witcher 3's new expansion is in safe hands, its lead writer literally wrote her thesis on Hearts of Stone: 'To probably prove to some of my professors that games are worthy'๐Ÿ–ฅ PC

If you need proof The Witcher 3's new expansion is in safe hands, its lead writer literally wrote her thesis on Hearts of Stone: 'To probably prove to some of my professors that games are worthy'

Mission accomplished.

๐ŸŽฎ The Witcher 3๐ŸŽฎ If you need proof The Witcher 3's new
PCNewsabout 4 hours ago