In this coding exercise you’ll learn how to build a pseudo random number generator in Ruby that dynamically creates a set of random numbers based on a pre-defined sequence.
Summary
Build a program that outputs a specific set of random numbers.
Exercise File
Exercise Description
The program should take in an integer as an argument and each time it’s called should generate the next number in an identical sequence.
Sample Use
Called the first time
i = pseudo_random 5 i.resume # 37 i.resume # 12 i.resume # 72 i.resume # 9 i.resume # 75
Called a second time
i = pseudo_random 5 i.resume # 37 i.resume # 12 i.resume # 72 i.resume # 9 i.resume # 75
Real World Usage
This exercise allows you to practice on a number of important development practices:
- Working with random numbers and overriding default randomness, this is key to building automated tests for processes that rely on random numbers.
- Implementing the ability for a program to maintain its state by leveraging the
Fiber
class.
Solution
Can be found on the solutions branch on github.