From computer simulations to cryptography, many applications rely on random number generators (RNGs). These generators must produce truly random numbers.
So how do we know if a random number generator is actually random? That’s where tests like the Craps test come in. The Craps test is a statistical test used to evaluate the randomness of a uniform random number generator.
In this article, we’ll cover the Craps test procedure, its different levels, how to interpret the results, and which random number generators it’s applicable to.
Understanding the Craps Test Procedure
The Craps test works by simulating the dice game of craps. The simulation relies on random numbers to represent the roll of the dice.
The test measures how often the player wins and how many tosses it takes to complete the game.
First level test: Probability of winning
The first level of the Craps test calculates the probability of winning. In theory, the probability of winning at Craps is 244/495, or about 0.4929.
This level also looks at how many tosses it takes to finish a game, which can be 1, 2, or more.
Analyzing the Distribution of Tosses
To figure out if the tosses are truly random, a statistical test called a Chi-square can be used. The Chi-square test helps us see whether what we actually observed lines up with what we’d expect to see if everything was random.
In this case, the degrees of freedom for the Chi-square test would be 20, which accounts for the different possible outcomes of the tosses.
If the Chi-square test shows that the distribution of tosses is significantly different from what we’d expect, then that tells us something’s up. It could mean the random number generator isn’t really producing a uniform distribution, or maybe there’s some kind of bias sneaking into the simulation.
First Level Test Outcome
If the simulation fails the first level test, it suggests that the random number generator might not be producing a uniform distribution or that there is a bias in the simulation.
Second Level Test: Ensuring Consistency
The second level test is basically running the first level test again. And again. And again. In fact, it’s a repetition of the first level test something like 200,000 times. This repetition is designed to show whether the results are consistent across many runs.
To analyze the consistency of the results, statisticians use tests like the Kolmogorov-Smirnov test and the Anderson-Darling test. These tests generate a “p-value,” which is essentially the probability that the results you’re seeing could have happened by chance.
In the second-level test, if the p-value is less than 0.05 or greater than 0.95, the test is considered to have failed, meaning that the results aren’t consistent enough to be considered truly random.
What do the results of the CRAPS test mean?
The CRAPS test produces a percentage. This percentage indicates the proportion of “second-level” tests that the random number generator failed.
So, what’s a good score? In general, a random number generator passes the CRAPS test if it fails less than 50% of the second-level tests.
If a generator fails the CRAPS test, you probably shouldn’t use it to generate truly random numbers. These generators may be predictable enough to pose a security risk.
In Closing
The Craps Test is a detailed statistical method for evaluating the randomness of random number generators (RNGs).
Using a reliable RNG is essential if you want to ensure the accuracy of a simulation or the security of your system. An unreliable RNG can undermine the validity of your results and make your system vulnerable to attack.
For these reasons, the Craps Test is a valuable tool in gaming, cryptography, scientific simulations, and any field where the quality of random numbers matters.