My Single Favorite Line Of Javascript

Math.random() unleashes serendipity and weirdness

Clive Thompson
Debugger
Published in
5 min readMar 6, 2022

--

A few years ago, someone on Quora asked “What’s the most powerful line of code ever written?”

The answers were pretty fun, and most were the ones you’d expect (if you’re a developer, anyway). Some folks praised the while and for loops, since they’re cornerstones of how get computers to do repetitive work and “take care of the most boring part of our lives.” Other coders talked about the power of print statements (making the computer talk), if-else statements (automated decision-making!), or the import command, which lets you automatically phagocytose someone else’s open-source code and use it in your own app.

Awesome choices, for sure. But for me, there’s one command that brings me a lot of joy:

Random

Pseudo-random-number generators! Most programming languages have one. If you’re writing in Javascript or Node, as I often am, the function is …

Math.random()

I humbly nominate this as the most weirdly magical — and surprisingly useful — line of code in existence.

--

--

Debugger
Debugger

Published in Debugger

Debugger is a former publication from Medium about consumer technology and gadgets. Currently inactive and not taking submissions.

Clive Thompson
Clive Thompson

Written by Clive Thompson

I write 2X a week on tech, science, culture — and how those collide. Writer at NYT mag/Wired; author, “Coders”. @clive@saturation.social clive@clivethompson.net