Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the .net random generator implemented?

Tags:

c#

.net

I mean the standard (?) random generator in .net /c#

Random random = new Random(seed);
random.next();

I know there are tens or hundreds of methods in literature, but I cannot find out which one the .net framework uses currently?

Reason for asking question: if I draw a LOT of random variables, will I ever return to the same sequence. I know some RNG have this undesirable property.

like image 283
willem Avatar asked Jun 24 '12 18:06

willem


1 Answers

Pseudo-random numbers are chosen with equal probability from a finite set of numbers. The chosen numbers are not completely random because a definite mathematical algorithm is used to select them, but they are sufficiently random for practical purposes. The current implementation of the Random class is based on a modified version of Donald E. Knuth's subtractive random number generator algorithm. For more information, see D. E. Knuth. "The Art of Computer Programming, volume 2: Seminumerical Algorithms". Addison-Wesley, Reading, MA, second edition, 1981.

http://msdn.microsoft.com/en-us/library/system.random.aspx

like image 199
nothrow Avatar answered Sep 20 '22 01:09

nothrow