
Random number simulation
The availability of random numbers is a necessary requirement in many applications. In some cases, the quality of the final application strictly depends on the possibility of generating good quality random numbers. Think, for example, of applications such as video games, cryptography, generating visuals or sound effects, telecommunications, signal processing, optimizations, and simulations. In an algorithm of this type, decisions are made based on the pull of a virtual currency, which is based on a randomly chosen value.
There is no single or general definition of a random number since it often depends on the context. The concept of random number itself is not absolute, as any number or sequence of numbers can appear to be random to an observer, but not to another who knows the law with which they are generated. Put simply, a random number is defined as a number selected in a random process from a finite set of numbers. With this definition, we focus on the concept of randomness in the process of selecting a sequence of numbers.
In many cases, the problem of generating random numbers concerns the random generation of a sequence of 0 and 1, from which numbers in any format can be obtained: integers, fixed points, floating points, or strings of arbitrary length. With the right functions, it is possible to obtain good quality sequences that can also be used in scientific applications, such as the Monte Carlo simulation. These techniques should be easy to implement and be usable by any computer. In addition, like all software solutions, they should be very versatile and quickly improved.
Important note
These techniques have a big problem that is inherent to the algorithmic nature of the process: the final string can be predicted from the starting seed. This is why we call this process pseudorandom.
Despite this, many problems of an algorithmic nature are solved very effectively and relatively simply using probabilistic algorithms. The simplest example of a probabilistic algorithm is perhaps the randomized quicksort. This is a probabilistic variant of the homonymous sorting algorithm, where, by choosing the pivot element, the algorithm manages to randomly guarantee optimal complexity in the average case, no matter the distribution of the input. Cryptography is a field in which randomness plays a fundamental role and deserves specific mention. In this context, randomness does not lead to computational advantages, but it is essential to guarantee the security of authentication protocols and encryption algorithms.
Probability distribution
It is possible to characterize a random process from different points of view. One of the most important characteristics is the probability distribution. The probability distribution is a model that associates a probability with each observable modality of a random variable.
The probability distribution can be either discrete or continuous, depending on whether the variable is random, discrete, or continuous. It is discrete if the phenomenon is observable with an integer number of modes. The throw of the dice is a discrete statistical phenomenon because the number of observable modalities is equal to 6. The random variable can take only six values (1, 2, 3, 4, 5, and 6). Therefore, the probability distribution of the phenomenon is discrete. The probability distribution is continuous when the random variable assumes a continuous set of values; in this case, the statistical phenomenon can be observed with an infinite or very high number of modalities. The probability distribution of body temperature is continuous because it is a continuous statistical phenomenon, that is, the values of the random variable vary continuously.
Let's now look at different kinds of probability distributions.
Uniform distribution
In many cases, processes characterized by a uniform distribution are considered and used. This means that each element is as likely as any of the others to be selected if an infinite number of extractions is performed. If you represent the elements and their respective probabilities of being extracted on a graph, you get a rectangular graph as follows:

Figure 2.2 – The probabilities of the elements
Since the probability is expressed as a real number between 0 and 1, where 0 represents the impossible event and 1 the certain event, in a uniform distribution, each element will have a 1/n probability of being selected, where n is the number of items. In this case, the sum of all the probabilities must give a uniform result, since, in an extraction, at least one of the elements is chosen for sure. A uniform distribution is typical of artificial random processes such as dice rolling, lotteries, and roulette and is also the most used in several applications.
Gaussian distribution
Another very common probability distribution is the Gaussian or normal distribution, which has a typical bell shape. In this case, the smaller values, or those that are closer to the center of the curve, are more likely to be extracted than the larger ones, which are far away from the center. The following diagram shows a typical Gaussian distribution:

Figure 2.3 – Gaussian distribution
Gaussian distribution is important because it is typical of natural processes. For example, it can represent the distribution of the noise in many electronic components, or it can represent the distribution of errors in measurements. It is, therefore, used to simulate statistical distributions in the fields of telecommunications or signal processing.
Properties of random numbers
By random number, we refer to a random variable distributed in a uniform way between 0 and 1. The statistical properties that a sequence of random numbers must possess are as follows:
Uniformity
Independence
Suppose you divide an interval, [0.1], into n subintervals of equal amplitude. The consequence of the uniformity property is that if N observations of a random number are made, then the number of observations in each subinterval is equal to N/n. The consequence of the independence property is that the probability of obtaining a value in a particular range is independent of the values that were previously obtained.