True Random Number Service
Necessary Preferences Statistics
Allow Selected Allow All
What’s this fuss about true randomness?
Perhaps you have wondered how predictable machines like computers can generate randomness. In reality, most random numbers used in computer programs are pseudo-random, which means they are generated in a predictable fashion using a mathematical formula. This is fine for many purposes, but it may not be random in the way you expect if you’re used to dice rolls and lottery drawings.
RANDOM.ORG offers true random numbers to anyone on the Internet. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs. People use RANDOM.ORG for holding drawings, lotteries and sweepstakes, to drive online games, for scientific applications and for art and music. The service has existed since 1998 and was built by Dr Mads Haahr of the School of Computer Science and Statistics at Trinity College, Dublin in Ireland. Today, RANDOM.ORG is operated by Randomness and Integrity Services Ltd.
Games and Lotteries
Lottery Quick Pick is perhaps the Internet’s most popular with over 280 lotteries
Keno Quick Pick for the popular game played in many countries
Coin Flipper will give you heads or tails in many currencies
Dice Roller does exactly what it says on the tin
Playing Card Shuffler will draw cards from multiple shuffled decks
Birdie Fund Generator will create birdie holes for golf courses
Q3.1 in the FAQ explains how to pick a winner for your giveaway for FREE
Third-Party Draw Service is the premier solution to holding random drawings online
Step by Step Guide explains how to hold a drawing with the Third-Party Draw Service
Step by Step Video shows how to hold a drawing with the Third-Party Draw Service
Price Calculator tells exactly how much your drawing will cost
Drawing FAQ answers common questions about holding drawings
Public Records shows all completed drawings going back five years
Drawing Result Widget can be used to publish your winners on your web page
Multi-Round Giveaway Service for verified video giveaways
Integer Generator makes random numbers in configurable intervals
Sequence Generator will randomize an integer sequence of your choice
Integer Set Generator makes sets of non-repeating integers
Gaussian Generator makes random numbers to fit a normal distribution
Decimal Fraction Generator makes numbers in the [0,1] range with configurable decimal places
Raw Random Bytes are useful for many cryptographic purposes
Lists and Strings and Maps, Oh My!
List Randomizer will randomize a list of anything you have (names, phone numbers, etc.)
String Generator makes random alphanumeric strings
Password Generator makes secure passwords for your Wi-Fi or that extra Gmail account
Clock Time Generator will pick random times of the day
Calendar Date Generator will pick random days across nearly three and a half millennia
Geographic Coordinate Generator will pick a random spot on our planet’s surface
Bitmaps in black and white
Hexadecimal Color Code Generator will pick color codes, for example for use as web colors
Pregenerated Files contain large amounts of downloadable random bits
Pure White Audio Noise for composition or just to test your audio equipment
Jazz Scales to practice improvisation for students of jazz guitar
Samuel Beckett’s randomly generated short prose
DNA Protein Sequence Randomizer (at Bio-Web)
Web Tools and Widgets for Your Pages
Integer Widget Wizard will put a mini-RANDOM.ORG on your web page or blog
Draw Widget Wizard will put the result of a paid drawing on your web page or blog
HTTP API to get true random numbers into your own code
Guidelines describe how to avoid getting in trouble
Banned Hosts lists who didn’t behave and have been blocked
Learn about Randomness
Introduction to Randomness explains what true random numbers are and why they’re interesting
History explains how RANDOM.ORG started and where it is today
Many Testimonials from folks who have found very creative uses for random numbers
Acknowledgements to all the generous folks who have helped out
Quotations about randomness in science, the arts and in life generally
Media Coverage and Scientific Citations lists popular print and scientific mention of the service
News about the latest additions to the site
Real-Time Statistics show how the generator is performing right now
Statistical Analysis explains how you test random numbers for randomness
Bit Tally shows how much randomness has been generated since 1998 (hint: lots!)
Your Quota tells how many random bits you have left for today
Contact and Help
FAQ contains answers to frequently asked questions
Newsletter appears at random intervals, but do sign up
Contact Details in case you want to get in touch
14 Answers 14
No, it is not possible to seed Math.random() , but it’s fairly easy to write your own generator, or better yet, use an existing one.
First of all, take care to initialize your PRNGs properly. Most of the generators below have no built-in seed generating procedure (for sake of simplicity), but accept one or more 32-bit values as the initial state of the PRNG. Similar seeds (e.g. a simple seed of 1 and 2) can cause correlations in weaker PRNGs, resulting in the output having similar properties (such as randomly generated levels being similar). To avoid this, it is best practice to initialize PRNGs with a well-distributed seed.
Thankfully, hash functions are very good at generating seeds for PRNGs from short strings. A good hash function will generate very different results even when two strings are similar. Here’s an example based on MurmurHash3’s mixing function:
Each subsequent call to the return function of xmur3 produces a new “random” 32-bit hash value to be used as a seed in a PRNG. Here’s how you might use it:
Alternatively, simply choose some dummy data to pad the seed with, and advance the generator a few times (12-20 iterations) to mix the initial state thoroughly. This is often seen in reference implementations of PRNGs, but it does limit the number of initial states.
The output of these PRNG functions produce a positive 32-bit number (0 to 2 32 -1) which is then converted to a floating-point number between 0-1 (0 inclusive, 1 exclusive) equivalent to Math.random() , if you want random numbers of a specific range, read this article on MDN. If you only want the raw bits, simply remove the final division operation.
Another thing to note are the limitations of JS. Numbers can only represent whole integers up to 53-bit resolution. And when using bitwise operations, this is reduced to 32. This makes it difficult to implement algorithms written in C or C++, that use 64-bit numbers. Porting 64-bit code requires shims that can drastically reduce performance. So for the sake of simplicity and efficiency, I’ve only considered algorithms that use 32-bit math, as it is directly compatible with JS.
Now, onward to the the generators. (I maintain the full list with references here)
sfc32 (Simple Fast Counter)
sfc32 is part of the PractRand random number testing suite (which it passes of course). sfc32 has a 128-bit state and is very fast in JS.
Mulberry32 is a simple generator with a 32-bit state, but is extremely fast and has good quality (author states it passes all tests of gjrand testing suite and has a full 2 32 period, but I haven’t verified).
I would recommend this if you just need a simple but decent PRNG and don’t need billions of random numbers (see Birthday problem).
As of May 2018, xoshiro128** is the new member of the Xorshift family, by Vigna & Blackman (professor Vigna was also responsible for the Xorshift128+ algorithm powering most Math.random implementations under the hood). It is the fastest generator that offers a 128-bit state.
The authors claim it passes randomness tests well (albeit with caveats). Other researchers have pointed out that fails some tests in TestU01 (particularly LinearComp and BinaryRank). In practice, it should not cause issues when floats are used (such as these implementations), but may cause issues if relying on the raw low bits.
JSF (Jenkins’ Small Fast)
This is JSF or ‘smallprng’ by Bob Jenkins (2007), the guy who made ISAAC and SpookyHash. It passes PractRand tests and should be quite fast, although not as fast as SFC.
LCG (aka Lehmer/Park-Miller RNG or MCG)
LCG is extremely fast and simple, but the quality of its randomness is so low, that improper use can actually cause bugs in your program! Nonetheless, it is significantly better than some answers suggesting to use Math.sin or Math.PI ! It’s a one-liner though, which is nice :).
This implementation is called the minimal standard RNG as proposed by Park–Miller in 1988 & 1993 and implemented in C++11 as minstd_rand . Keep in mind that the state is 31-bit (31 bits give 2 billion possible states, 32 bits give double that). This is the very type of PRNG that others are trying to replace!
It will work, but I wouldn’t use it unless you really need speed and don’t care about randomness quality (what is random anyway?). Great for a game jam or a demo or something. LCGs suffer from seed correlations, so it is best to discard the first result of an LCG. And if you insist on using an LCG, adding an increment value may improve results, but it is probably an exercise in futility when much better options exist.
There seems to be other multipliers offering a 32-bit state (increased state-space):