4 ms·
I once wrote a small script (in C#) to pick a few tens out of a few 1000s. I got weird repeats. I switched to a cryptographically secure RNG, and the repeats we
by Semaphor 3y ago
I once wrote a small script (in C#) to pick a few tens out of a few 1000s. I got weird repeats. I switched to a cryptographically secure RNG, and the repeats were gone. It was probably pure chance, but I stopped using the normal random function ever since ;)
- physicles 3y agoDo you still have your original code? Finding out if the weird repeats were real, and especially why, would make a super interesting blog post.
- Semaphor 3y agoThe old code was var r = new Random() ;) I'm assuming I either hit an PRNG bug (after all, I encountered a compiler bug in university already), or more likely, that I simply imagined the issue or bad bad luck with the data. Never did a statistical analysis after all.
- GuB-42 3y agoJust for curiosity sake, I looked at the standard RNG in C# and it is indeed flawed, but probably not enough to be seen unless you are doing formal tests. In [1] it says that numbers have a 0.5034 probability of being odd due to rounding errors in the algorithm that picks a number in a range, which is unacceptable for a simulation, but may actually be better than a real coin toss [2]. The raw RNG is also flawed but not that badly [3] [1] https://fuglede.dk/en/blog/bias-in-net-rng/ https://fuglede.dk/en/blog/bias-in-net-rng/ [2] https://arxiv.org/abs/2310.04153 https://arxiv.org/abs/2310.04153 [3] https://gist.github.com/fuglede/772402ecc3997ada82a03ce65361781b https://gist.github.com/fuglede/772402ecc3997ada82a03ce65361...
- Semaphor 3y agoOkay, now you made me want actually look into that ;) I should be able to recreate the old code (it was years ago, but I still have the script) and make a comment if I end up actually finding statistical anomalies.
- Semaphor 3y agoIt will have to stay a mystery, looking at distribution, both algorithms looked the same.