The attached source code is the C# implementation of the Mersenne Twister algorithm, developed by Makoto Matsumoto and Takuji Nishimura in 1996-1997. This algorithm is faster and more efficient, and has a far longer period and far higher order of equidistribution, than other existing generators.
Histogram Code in C#
Extended Euclidean Algorithm
An update to Trevor's code, which implements System.Random and incorporates new research about the Mersenne Twister algorithm when generating double floating point values, can be found here: http://code.msdn.microsoft.com/MersenneTwister/ .