The example question for these solutions can be found on my website (click here).
2.1 Random Numbers
To use the new random number generator we need to include the random library, the cmath
library for any calculations and also iostream to show results onscreen. We first create a new
project with an empty program with the correct libraries, and then declare a variable of type
mt19937. This declares a new random number generator, which generates pseudo random
sequence of integers defined by the Mersenne Twister algorithm. A computer can only
generate a random sequence of integers, but of course we can then take that sequence
of integers and convert it to any required distribution. Some of the conversions are
simple but others are more complex, luckily we now have inbuilt c++ conversion to
all standard distributions (more on this later). This means you will always have to
create a generator to pass as an argument to the probability distribution you want to
generate.