WeSearch

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

https://www.pcgamer.com/author/andy-edser/· ·6 min read · 0 reactions · 0 comments · 1 view
#balatro#random number generation#mouse jitter#game development#code analysis
 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
⚡ TL;DR · AI summary

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.

Key facts
Original article
PCGamer latest · https://www.pcgamer.com/author/andy-edser/
Read full at PCGamer latest →
Full article excerpt 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. 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. window.sliceComponents = window.sliceComponents || {}; externalsScriptLoaded.then(() => { window.reliablePageLoad.then(() => { var componentContainer = document.querySelector("#slice-container-newsletterForm-articleInbodyContent-EoL6MGfEuCUC3QScBvSioZ"); if (componentContainer) { var data = {"layout":"inbodyContent","header":"The biggest gaming news, reviews and hardware deals","tagline":"Keep up to date with the most important stories and the best deals, as picked by the PC Gamer team.","formFooterText":"By submitting your information you agree to the <a href=\"https:\/\/futureplc.com\/terms-conditions\/\" target=\"_blank\">Terms & Conditions<\/a> and <a href=\"https:\/\/futureplc.com\/privacy-policy\/\" target=\"_blank\">Privacy Policy<\/a> and are aged 16 or over.","usDisclaimerFooterText":"By signing up, you agree to our <a href=\"https:\\\/\\\/futureplc.com\\\/terms-conditions\\\/\" target=\"_blank\">Terms of services <\/a> and acknowledge that you have read our <a href=\"https:\\\/\\\/futureplc.com\\\/privacy-policy\\\/\" target=\"_blank\">Privacy Notice<\/a>. You also agree to receive marketing emails from us that may include promotions from our trusted partners and sponsors, which you can unsubscribe from at any…

This excerpt is published under fair use for community discussion. Read the full article at PCGamer latest .

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Email

Discussion

0 comments

More from PCGamer latest