Ok, everybody already knows the default Random Number Generator in .NET stinks for anything other than really simple usage. If this is news to you, take a moment and go read
this article first, then come back here.
In HA! I use a C# implementation of the Mersenne Twister for RNG, but there is another option. After seeing John Lunsford's excellent Crypto presentation at the Columbia, SC .NET User Group, I decided to start playing with the RandomNumberGenerator class in the System.Security.Cryptography namespace.
I haven't done a comprehensive analysis on performance yet, but "they say" that the Mersenne Twister is faster and more random. Depending on your needs, the Mersenne Twister might still be the better way to go. However, both of these are so much better than System.Random, and the differences between them so negligible, that it might not matter. Depends on your needs, of course.
The Crypto stuff works like this:
Dim b(10) As Byte
System.Security.Cryptography.RandomNumberGenerator.Create.GetNonZeroBytes(b)
That gives me an array of 10 numbers, each between 1 and 255. There is another method, called GetBytes that includes 0 in the results.
Of course, if you want a range OTHER than 1 - 255, you have to do a little extra work. Let's say you want numbers in the range of 1 - 20, all you do is MOD the resulting number by 20 and then add 1. The following code will take each value and adjust it down to the specified range:
For intCtr = 0 To 9
b(intCtr) = (b(intCtr) Mod 20) + 1
Next
Now you have an array of 10 numbers, each between 1 and 20. What you do with them at this point is largely up to you. If you need pseudo-random numbers larger than 255, then I think you're definitely better off using the Mersenne Twister. For simulating die rolls, such as 1-4, 1-6, 1-8, 1-10, 1-12, 1-20 or 1-100 this methods works great, is extremely simple to use and doesn't require the additional effort of adding something as complex as a Mersenne Twister to your code.