5 ms·
What about unit tests?
by thrownaway2424 11y ago
What about unit tests?
- dspillett 11y agoProduce a set of random numbers once and store them as part of the test set. That way your test is independent of the black box which is your RNG. Or make your own simple RNG - in these cases you are looking for "arbitrary, definitely not just sequential" rather than cryptographically random (or, indeed, truly random at all). If you rely on the order of the output, for reliably consistent test cases in this instance, avoid using black-box RNGs which could change implementation under your nose without much or any warning.
- Veedrac 11y agoCryptographically random isn't the aim here - pseudorandom is. A seedable black-box RNG that guarantees what seed corresponds to what stream is way simpler to use than a list of random numbers, IMHO. It's the difference between copying one number and copying a million.
- dspillett 11y ago> Cryptographically random isn't the aim here We are agreeing here. > A seedable black-box RNG that guarantees what seed corresponds If you can control when the blackbox gets updated, or the blackbox carries a guarantee of stable output for any given seed over the while time of its existence, yes. But if you are using OS provided RNGs, as a for instance, their behaviour is not defined (well they are, but those definitions are not set in stone) and may change as kernel updates happen. That is why I suggest "making your own simple PRNG". This could be as simple as picking a known documented algorithm as implemented by a particular library and using that in your test cases - it doesn't need to be as much as writing your own function even.
- Veedrac 11y agoRight... but nobody's suggesting replacing the OS's RNG.