What is random?
Randomness – sounds very simple and is evident all around us in the nature. Be it the count of the sea waves in a minute, waving of leaves (or branches) of a tree or chirping of birds. All are random. Pure random. And is indeterministic – unpredictable – by human beings. However, even the most complex mathematical equations cannot be written to predict or determine the events in the nature. Even the smartest of the computer cannot be used to simulate or churn out the indeterministic behaviour of these random events.
So, then what is randomness? Are these natural events purely random? – probably yes, probably no. We will come back to this question towards the later part of this blog.
Before we get into the randomness of the event in the nature or the physical world that surrounds us, let’s try to understand the randomness in mathematical context.
What is a pure random number mathematically?
Short Answer: There is no pure Random number in mathematics.
In mathematics even the most complex equations cannot generate the pure random number. It can only create a pseudo-random number. Why?
It is because the output from any mathematical model will always depend on an input to start with (initial value) and the mathematical model which convert the input into a meaningful output – random number in this case.
However, if the above is repeated by anyone – say gives same input and formulates the same mathematical model – then one will get exactly same result or output. So, it is not random. It is predictable, deterministic and moreover reproducible.
So, then how to get a pure random number mathematically or programmatically in software? Before we answer this question let’s understand something called Chaos (chaotic number).
What is a chaotic function?
A chaotic function is a periodic function with infinite time period. The output generated by a chaotic function may appear to be random but it is not. The only point is since the periodicity is infinite, the numbers do not get repeated and we do not see any pattern in it.
Let’s understand the chaotic function by a simple example.
Below is a simple sine wave form:
A, amplitude, the peak deviation of the function from zero.
ϕ , phase, specifies (in radians) where in its cycle the oscillation is at t = 0.
ω = 2πf, angular frequency, the rate of change of the function argument in units of radians per second
or, ω = 2π/T, where T = time-period of the wave form
It takes no genius to guess that the above wave-form has a fixed time-period of T and hence, it completes around 2 to 2.5 cycles between point A and B.
Now, what if we expand this sine wave, that is increase its time period as below:
So, here the time-period has increased to one T between points A and B. But still appears to be deterministic in characteristics.
Now, What if we further expand it such that only a small part of sine wave is covered between A and B as shown below:
Since we have been doing this exercise from the beginning we can easily guess that it is just a part of sine wave (around a quarter of the sine wave) between point A and B. We can confidently say that it has a periodicity of T which is probably 4 times the duration between point A and B.
But what if this waveform was presented in the first place? Then mathematicians may have guessed it as a linear function or some kind of logarithmic or exponential function. It can be guessed as a sine wave as well but not with surety. So, in the deficiency of any specific mathematical model of this wave form it will be difficult for anyone to determine its value at any instance of time very accurately.
Now, here is the magic part. Till now we are assuming that the points A and B are within finite ranges and are accessible. However, what if these points stretches to infinity. Then our 1/4th of T becomes infinity and, of course, making T = infinity in the below equation (Time period = infinity will make frequency as 0).
So, anyone presented with this wave-form will assume it as a random function whose output cannot be determined at any point of time till infinity. But that is not correct.
Why then chaotic function is not a random function? As there is no pattern in the output due to infinite periodicity, doesn’t it qualifies to be a random function?
Unfortunately No. A chaotic function can not be qualified as a random function because it violates one of the principle rules of random number – indeterministic – that is a pure random number should be indeterministic by its characteristics. Whereas a chaotic function output though does not follow any pattern or is not discernible by normal human brain but it is deterministic. In factual sense, a chaotic function is also a mathematical function with an infinite time period. So, if anyone who knows the function and can figure out the initial value or the current value of the function, can determine the output of the chaotic function at any point of time. Hence, the chaotic function is rendered as non-random function.
Then How to get a pure random number?
This is an important open question in the field of mathematics. More so with the increased use of software, the need for pure randomness has increased. Specially in the areas of software testing and mostly where the software or the product interacts with the physical environment. Why?
It is because the physical world is random. Yes, random. Is it purely random or just an infinite time-period chaotic function. Probably we do not know. But it is random for human beings, even if it is a particular mathematical model with some initial value, but both is not known to the human beings. Hence, making it pure random for the human society. Now, as the software interacts with the random parameters of the world it is imperative to test them in a pure random environment before deploying them for the actual use.
The mother nature started this whole world billions of years back. And even with all the advancement in science and technology also humans do not have a way to determine the exact mathematical model followed by nature in the physical world. Or if at all nature follows a certain model itself can’t be proved.
Moreover, there are thousands of nature’s physical parameter we interact with in continuous basis at any point of time. For example – ambient temperature, intensity of light at any location on our planet, speed of wind, count of waves in the sea, motion of a leaf in a tree, number of droplets of rain-water and so on. I can keep on writing a never ending list of physical parameters which, we, as a human interact on daily basis. But the point here is we cannot predict – yes, we cannot determine with precision and accuracy any of these parameters. Meteorological department does a fairly good job. But at the end they also give some approximate estimate and not the precise values.
Further, I will like to add that apart from the mathematical model, which is unknown, we do not even have the initial value or the starting time of any of these parameters. Hence, making these parameters almost indeterministic.
So, the crux is that yes, these physical parameters of the world can be considered as pure random in the narrow band of time-period of human existence. Even if they are chaotic model from nature’s bigger perspective (time-frame), but for us we can consider the nature parameters as pure random.
How to get the pure random number in my software?
Building on my above argument, if we can consider any of these physical parameters (or to make it more complex – a mixture of physical parameters), such as – temperature, wind speed, counts of waves, number of birds on a tree – measure them and take these data live in the software then we can generate a purely random number. It will be pure randomness as no one can guess, predict, determine or deterministically state the value of these random numbers at any point of time – either in the past or future.
But is it so easy to get this natural parameters in our software? More so, most of the software runs in a controlled environment on servers or clouds. So, how to integrate the randomness of the nature in our software?
Yes, there are challenges. Bringing the physical parameters into software may not be easy. But with the advent of different technology it is not that much difficult.
Firstly, software running on a specific hardware such as smartphone Apps, automobile software running in cars or software running on physical machines do have access to various physical parameters from your device. One such example is discussed in the below tutorial:
However, what about the software running on some servers such as a cloud?
For those software also, one can always try to access data which is publicly available and purely dependent on natural phenomenon. For example – Stock Market data published by stock exchange, temperature data published by meteorological department, etc.
One can argue stock prices are not a natural but a man-made phenomenon (data). Probably, no. The stock prices are result of thousands of traders interacting with each other. The reaction of every stock trader (human being) is very different and very much depends on their interaction with the nature at that point of time.
Similarly , the precise temperature data published by meteorological department is pure random and not something which they have predicted or determined mathematically.
Of course, one can consider other physical data as well and the above are just illustration for demonstration.
So, accessing the physical parameters is the only possible approach to generate a pure random number in software.
In essence, it is nearly impossible to generate a pure random number artificially. Once again it is nature which rescues us. We have to rely upon it to get the pure randomness.
We hope you enjoyed reading this article.
The author of this page can be contacted at https://programmerworld.co/contact/ or email: firstname.lastname@example.org