Comment

Comment by addictedcs

First example I've checked is wrong [1]. Shuffle a list, with a static Random object initialization. Using a static random object is not thread-safe in .NET.

"One common solution is to use a static field to store a single instance of Random and reuse it. That’s okay in Java (where Random is thread-safe) but it’s not so good in .NET – if you use the same instance repeatedly from .NET, you can corrupt the internal data structures." [2]

Very often the very same resources which claim to be the source of truth provide bad code examples.

[1] https://www.programming-idioms.org/cheatsheet/Csharp

[2] https://codeblog.jonskeet.uk/2009/11/04/revisiting-randomnes...

parent addictedcs 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton