Join us at TNW Conference 2022 for insights into the future of tech →

The heart of tech

This article was published on December 17, 2015

Google Chrome’s JavaScript engine finally returns actual random numbers

Google Chrome’s JavaScript engine finally returns actual random numbers
Owen Williams
Story by

Owen Williams

Former TNW employee

Owen was a reporter for TNW based in Amsterdam, now a full-time freelance writer and consultant helping technology companies make their word Owen was a reporter for TNW based in Amsterdam, now a full-time freelance writer and consultant helping technology companies make their words friendlier. In his spare time he codes, writes newsletters and cycles around the city.

Over the years, multiple studies have found that Google Chrome’s V8 JavaScript engine was returning not-so-random numbers when you called the Math.random() function.

Today that’s been fixed, with the release of Chrome 49, which will be available soon. Math.random() is the most frequently used way to generate randomness in Javascript, which is an important component of many web applications.

The study had previously found that the randomness wasn’t really random at all, eventually falling into patterns given enough time.

To fix the bug Google needed to switch to a new pseudo-random number generator called xorshift128+ which fixes the not-quite-random problem found in the older MWC1616 algorithm.

xorshift128+ results in random numbers that are actually random and offers significant performance improvements, however is not cryptographically secure, so shouldn’t be used to create GUIDs or other secure hashes.

Google says it was happy to fix the problem and is encouraging anyone who spots an abnormality, big or small, to file issues on its bug tracker in the future.

➤ There’s Math.random(), and then there’s Math.random() [V8 Engine]

Also tagged with