I am interested in learning more about Random Number Generation. Recently, I found out about an algorithm called "RANDU" (https://en.wikipedia.org/wiki/RANDU), which was an early algorithm for generating random numbers.
Using the R language, I implemented it below:
v = rep(0,100)
v[1]=3
for (j in 1:100) {
v[j+1]=(65539*v[j])%%(2^31)
}
i = 1:101
range01 <- function(x, ...){(x - min(x, ...)) / (max(x, ...) - min(x, ...))}
rand_data = data.frame(i,v)
rand_data<span class="math-container">$int_version = range01(rand_data$</span>v)
head(rand_data)
i v int_version
1 1 3 0.000000e+00
2 2 196617 9.201486e-05
3 3 1179675 5.520835e-04
4 4 5308497 2.484362e-03
5 5 21233907 9.937413e-03
6 6 79626969 3.726522e-02
plot(rand_data$v, type = "b", main = "100 Random Real Numbers with Randu")
Naturally, this lead me to the following question:
- How do we know that these 100 numbers are truly random - Is there some mathematical proof for this?
- Why does this RANDU algorithm work - Is there some mathematical proof for this?
I tried to look into this, but I couldn't find a straight answer. Can someone please provide any comments?
Thank you!
Note: Apparently you can use the Chi-Square Test to find out if a random sequence of numbers has a "uniform distribution" (https://stats.stackexchange.com/questions/406406/test-of-uniform-distribution-using-ks-test-and-chi-square-in-r, Is there a simple test for uniform distributions? ... but I am not sure why the Chi-Square Test can detect if random numbers have a uniform distribution). I performed this test in R:
ks.test(rand_data$int_version, "punif", min(rand_data$int_version), max(rand_data$int_version))
One-sample Kolmogorov-Smirnov test
data: rand_data$int_version
D = 0.079507, p-value = 0.5457
alternative hypothesis: two-sided
Based on these results, the p-value is significantly greater than a standard tolerance level (e.g. alpha = 0.05) - therefore, there is sufficient statistical evidence to accept the Null Hypothesis and conclude that these random numbers correspond to a uniform distribution.