Deterministic "randomness" in Swift

It would be quite useful to have deterministic randomness during development. I remember I was chasing a bug and succeeded only when I replaced all those various "random" calls to my wrappers which I based on some simple pseudorandom generator and thus removed the main sources of randomness (*) to get the reproducible case I was finally able debug and fix. This approach has it's limitations (third party components or the system itself can have calls to random and it's not easy to patch that).

(*) some remaining randomness (e.g. due to timing variation of code execution or due to effectively "random" memory addresses you are getting back from malloc) is inevitable.

1 Like