Yeah, that could actually work. Because the seed is passed in, the output _should_ be predictable.
Mark Erikson
21

Great point.

The reason I chose a different approach from the one you mention is because it removes the impure ‘random’ function from the application logic and makes it an application input, which seems to better follow functional programming guidelines and has advantages for debugging.

For example if we generate the random number in an action dispatcher, we won’t be able to reproduce a given state by following the same steps twice (we can of course reproduce the state by replaying the redux actions). Using a seed and pseudo number generator we can guarantee (when we use a static seed) that every given set of actions will result in the same output, which is useful for development.

We can even extend this concept to production provided that the user’s random number seed is exported along with other relevant debugging info when they report the issue (which might be worth doing when developing games).

Show your support

Clapping shows how much you appreciated Joshua Ohlman’s story.