170 likes | 281 Views
Most Random Number. Tom Carter CSSS 2004. Here’s a somewhat strange question. What is the most random number between 1 and 1000?. How to go at it?.
E N D
Most Random Number • Tom Carter • CSSS • 2004
Here’s a somewhat strange question . . . • What is the most random number between 1 and 1000?
How to go at it? • Let’s try to develop a “probability distribution function” representing some general notion of a “randomness” property for numbers . . . :-)
Too simple. We do get a unique maximum at 500, but that can’t be right. • As everybody knows, you never get the actual data value. There are always “errors” that push you away from the real value. • So, we should overlay a repelling “error dark-force” on top.
Now we’re getting somewhere! • But, we don’t have a unique maximum any more. • There must be a bias in one direction or the other, mustn’t there?
Aha! We forgot about Benford’s law on the distribution of significant digits. • One form of Benford’s law says that on average, the proportion of numbers having first digit less than d will be about log(d+1) for d = 1, 2, . . ., 9. • Another way to say this is that the distribution will be approximately 1/(d+1), so we’ll overlay a power law
Now we’re almost done. We have a single maximum, and it is not the simplistic 500. • One more piece. Random numbers must not have “special properties,” right? • So, they probably won’t be divisible by small primes like 2 or 3 or 5. • Let’s write a couple of small MatLab functions for all this.
function r = mrn(x) %"most random number" function :-) r = (1/((x/100) + 1)) * (1 - normpdf(x, 500, 70) normpdf(500,500,70)) * normpdf(x, 500, 167); function r = maxrn % search for "most random number" using mrn(x) maxval = 0; maxrn = 0; for n = 1:1000 if rem(n,2) ~= 0 & rem(n,3) ~= 0 & rem(n,5) ~= 0 & mrn(n) > maxval maxval = mrn(n); maxrn = n; end end r = maxrn;
Now we run our function, and there it is, the most random number between 1 and 1000: >> maxrn ans = 347
What about more general versions of this? • In other words, what about the most random number between 1 and 10, 1 and 100, 1 and 10000, etc.?
function r = mrng(x,maxn) %"most random number" function :-) r = (1/((10*x/maxn) + 1)) * (1 - normpdf(x, maxn/2, 0.07*maxn)/normpdf(maxn/2,maxn/2,0.07*maxn)) * normpdf(x, maxn/2, maxn/6); function r = maxrng(maxn) % search for "most random number" using mrng(x,maxn) maxval = 0; maxrn = 0; for n = 1:maxn if rem(n,2) ~= 0 & rem(n,3) ~= 0 & rem(n,5) ~= 0 & mrng(n,maxn) > maxval maxval = mrng(n,maxn); maxrn = n; end end r = maxrn;
Summary of most random numbers: • 1 to 10: 7 • 1 to 50: 17 • 1 to 100: 37 • 1 to 500: 173 • 1 to 1000: 347 • 1 to 10,000: 3,479 • 1 to 100,000: 34,799 • 1 to 1,000,000: 347,971