Reputation: 1322
Let me preface this question by stating that I'm not a C# developer. I'm a C developer by trade and choice. But I have to use Visual C# for a class I'm taking.
I've been reading up on the differences between cryptographically secure pseudorandom number generators and System.Random. Everyone seems pretty clear that RNGCryptoServiceProvider is much more strongly random, but also slower.
For our algorithm in a group project we'll be using 3 random nodes out of a given (fixed) list, as many times as we can in 25 seconds, to score edges on paths between them.
In order for our algorithm to be "complete" we need to be sure that every node will get picked as close to the same number of times as every other node. In order for our algorithm to be "optimal" (or as close as possible, since we're ok with approximation) we need to do the scoring pass as many times as possible within that 25 second (or any other arbitrary) deadline.
Given that we'll be using a single instance of Random, but that we'll be running a loop that will call Random.Next() 3 times in rapid succession, and which will repeat as many times as possible, will Random produce a reasonably uniform distribution? Or will we need to incur the extra cost of RNGCryptoServiceProvider to ensure we don't have any nodes that get skipped over completely?
Upvotes: 0
Views: 213
Reputation: 39023
Random will produce a uniform distribution. The problem with Random is that it's somewhat predictable - from a few random numbers you can deduce the rest of the random number stream. Since this isn't a problem for you, and you're only worried about uniform distribution, Random should be enough.
Upvotes: 1