Random Function
Explore how to create two overloaded random functions in C++. Understand the Linear Congruential Generator algorithm used for producing pseudo-random numbers, and implement these functions to generate both integer and ranged random values. This lesson provides insights into function overloading and random number generation techniques.
We'll cover the following...
Problem
Write a program that provides two overloaded random( ) functions. The first one generates an integer random number, whereas the second generates a random number that lies within the range passed to the random( ) function.
Coding solution
Here is a solution to the problem above.
Explanation
The program uses a Linear Congruential Generator (LCG) algorithm that yields a sequence of pseudo-random numbers calculated with a discontinuous piecewise linear equation. The generator is defined by the recurrence relation:
...