Seedable JavaScript random number generator

scunliffe picture scunliffe · Jan 8, 2009 · Viewed 132.1k times · Source

The JavaScript Math.random() function returns a random value between 0 and 1, automatically seeded based on the current time (similar to Java I believe). However, I don't think there's any way to set you own seed for it.

How can I make a random number generator that I can provide my own seed value for, so that I can have it produce a repeatable sequence of (pseudo)random numbers?

Answer

David Bau picture David Bau · Feb 3, 2010

One option is http://davidbau.com/seedrandom which is a seedable RC4-based Math.random() drop-in replacement with nice properties.