4 ms·
Pure (functional) random generator lib for JavaScript/TypeScript
- dubzzz 9y agoJust to add a bit of context and describe a subject where such generator can be useful. Let's say we are building a turn by turn game in JavaScript or TypeScript (2048 for instance). Each time the player plays a round the IA uses an internal random generator to guess its next move (adding a 2 or 4 in the grid). If we want to add some kind of cancel operation, then replaying the user input might lead to a completely different situation given we use unpure random generator. Using a pure one we just have to ask the generator again for its value. Such problem can easily be encountered in implementations of 2048 allowing the back operation.