Same random seed in Matlab and R Same random seed in Matlab and R r r

Same random seed in Matlab and R


I'm finding it difficult to get the same random numbers in R and MATLAB - even using the same seed for the same algorithm (Mersenne Twister).

I guess it's about how they are implemented - even with the same seed, they have different initial states (you can print and inspect the states both in R and MATLAB).

In the past when I've needed this, I generated random input, saved it as a file on disk, and fed it to both MATLAB and R.

Another option is to write C wrappers for a random number generator (there are many of these in C/C++) both for R and MATLAB and invoke those instead of the built-in ones.