JavaScript: Random number generator
Last update: 26 Mar 23:20
0
Students
Random.js
Implement a random number generator provided by the Random
class. The object interface includes three functions:
- Constructor. Takes a seed, the initial number of the pseudorandom number generator
getNext()
returns a new random numberreset()
resets the generator to the initial value
Export class as default.
Examples
const seq = new Random(100);
const result1 = seq.getNext();
const result2 = seq.getNext();
result1 !== result2; // true
seq.reset();
const result21 = seq.getNext();
const result22 = seq.getNext();
result1 === result21; // true
result2 === result22; // true
Tips
- The easiest way to implement random numbers is a linear congruential generator
For full access to the challenge you need a professional subscription.
A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.