[R] Question on RNG

Petr Savicky savicky at praha1.ff.cuni.cz
Sat Aug 6 21:37:22 CEST 2011


On Fri, Aug 05, 2011 at 11:47:49PM +0530, Ron Michael wrote:
> Hi all, I have happened to work on MS .NET for sometime now, and I found that this language offers RNG what is called as Donald E. Knuth's subtractive random number generator algorithm (found here: http://msdn.microsoft.com/en-us/library/system.random.aspx#Y12).
>  
> Here I was wondering whether R also have same RNG in it's inventory, so looked at ?set.seed. There I found 2 related RNGs namely 'Knuth-TAOCP-2002', 'Knuth-TAOCP'. Can somebody guide me what is the most related RNG with .Net's?
>  
> I also want to have R to draw random number from that RNG, given I set a seed. My goal is to have same set of random numbers in .Net & R, so that I can match and see and compare the performance for some further calculations, which are based on random numbers in both .Net & R.

Hi.

R uses Mersenne Twister generator as the default one. There are
implementations of this generator in different laguages, including C#.
Links may be found on Wikipedia and also at the home page of
Mersenne Twister

  http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

Different implementations of Mersenne Twister differ in some
details, in particular in the initialization algorithm.
In order to obtain the same stream of numbers, it will be
needed either to copy the initialization algorithm from R
to the C# implementation or vice versa. I can provide more
detail off-list, if you are interested.

Petr Savicky.



More information about the R-help mailing list