The Simpsons have made some truly obscure references over their 32 seasons on the air, but what’s with the surreal “1000 monkeys with a 1000 typewriters” joke in season 4’s classic "Last Exit to Springfield?" With almost 700 episodes to their name and counting, it’s fair to say that primetime TV institution The Simpsons has come a long way since the first television outing of Springfield’s favorite family, a Christmas special entitled “Simpsons Roasting On An Open Fire.”

In their many years on the air, The Simpsons have pulled off all manner of jokes, with the show willing to do just about anything for a laugh. The style of gags ranges from the simplest slapstick to the most ambitious multi-season set-ups for clever punchlines. The much-imitated series from co-creators Sam Simon, James L Brooks, and Matt Groening, is famous for the range of its humor, which often included some seriously obscure references alongside the sillier gags.

Related: The Simpsons' Most Impressive Gag (Is One You Probably Missed)

With the comedic ambition of the early Simpsons writing in mind, it’s fair for viewers to wonder where the memorably bizarre “a 1000 monkeys with a 1000 typewriters” premise comes from. The brief scene appears in "Last Exit to Springfield" (an outing frequently called the best Simpsons episode ever) and sees Mr. Burns trying to impress Homer with the many absurd features of his vast mansion. Among these is a room containing ‘1000 monkeys with 1000 typewriters,’ who Burns claims will soon have written the greatest novel known to man. It’s a hilariously inexplicable scene - particularly the goofy pay-off “you stupid monkey!” when viewers see the overworked simians aren’t quite there yet - but what is this gag referencing? It’s actually a nod to the “infinite monkey theorem,” a famous math-based thought experiment.

Simpsons Burns Monkey

 

The theory argues that an infinite number of monkeys given an infinite number of typewriters would inevitably end up writing every combination of letters, including the collected works of Shakespeare. However, it would likely take all the monkeys in the known universe (and a lot more than The Simpsons' 1000) the duration of the universe’s existence to write Hamlet — but there is still a chance it would happen. Without a grounding in advanced mathematics, the point of this strange thought experiment seems obtuse, but it was mostly designed so that mathematicians could contextualize the idea of “almost surely” and so it’s not one with much applicability in everyday life.

Despite this, the infinite monkey theorem has nonetheless been referenced not only in The Simpsons, but in Family Guy - where said monkeys are arguing over how to phrase a line from Romeo and Juliet - That 70s Show, Veronica Mars, and even Downton Abbey. It’s strange to see that such a specific and odd thought experiment has had an outsized impact on popular culture, but what’s not surprising is the fact that of course, as South Park said, The Simpsons did it first.

More: The Simpsons Failed Barney (By Copying His Own Tragic Masterpiece)