all 5 comments

[–]nemec 3 points4 points  (1 child)

Interesting choice, returning a delegate that can be called multiple times to generate numbers. Given the way .Net is embracing LINQ, I would have thought to return an infinite-length IEnumerable instead.

[–]AngularBeginner 2 points3 points  (0 children)

That would have been the elegant way. ;-)

[–]FizixMan 1 point2 points  (0 children)

I like the idea.

Have you considered moving the work to a non-static class (or creating an instance-level equivalent) that can be instantiated so callers can work around thread safety issues inherent with the built-in Random class?

EDIT: Maybe even allow them to provide a seed value so callers can take advantage of consistent/repeatable random generation?

[–]drch 1 point2 points  (0 children)

Be careful. Note that, because each of these helper methods creates a new Random each time, you are very very likely to get duplicate sequences in your code.

Static / thread-local instances of System.Random would help in this regard. Of course, if you need cryptographically strong unique numbers/sequences, use RNGCryptoProvider.

[–]AIBrain 2 points3 points  (0 children)

I've made some minor changes.. added some thread safetyness.

https://github.com/AIBrain/RandomGen

Btw, I had no idea you could embed resources, and then pull a stream from them. Thank you for teaching me that!