A linear congruential generator is a simple method often used to generate pseudorandom number sequences. The sequence starts with an arbitrary number (called a "seed"). Then to generate the next number in the sequence, multiply by a constant ("multiplier"), then add another constant ("increment").
In this problem, we will use a seed of 0, a multiplier of 134775813, and an increment of 1. Thus, the first few numbers in the sequence are:
- 0th: 0 (This is the seed. We'll call it the 0th number)
- 1st: 1 (0 × 134775813 + 1)
- 2nd: 134775814 (1 × 134775813 + 1)
When the number overflows, keep the lowest 32 bits (i.e., mod 232). This happens automatically without extra code.
Write a function that returns the nth number in the above sequence.
unsigned random (unsigned n);
Expected solution length: Around 10 lines.
Write your solution here