2.6. Random variables

If a variable holds the values of its definition domain at random, we speak of a random variable.

In simulations, games, and randomized algorithms, random variables are of importance for which the distribution of the individual values is known, that is, for which we know the probability with which the variable takes on a certain value. We already saw an example of this in Section 2.5.1. There we simulated a fair dice with the help of the class random_source whose individual numbers are all thrown with the same probability of 1/6. The variable “number” is a uniformly distributed random variable. The class random_source serves for creating uniformly distributed random variables.[26]

But what, if the values of the variables are not uniformly distributed? If we want to simulate for example a loaded dice, with which the number “6” is thrown more frequently than the other numbers? For such non-uniformly distributed random variables LEDA keeps ready the classes random_variate and dynamic_random_variate.

The class random_variate serves for creating random values whose distribution does not change and is known in advance. In contrast, random values whose distribution changes during the program run can be created with the class dynamic_random_variate.

[26] To obtain an other domain W than the integral interval I created by random_source, we can use for example the values created from I as indices of an array which contains the desired random values W. By this means arbitrary, even non-integral random values can be created (with equal probability).