Why does the MRG32k3a return only positive values in the internal state matrix?
Show older comments
The MRG32k3a random number generator from L'Ecuyer should have internal state vectors of signed long (ranging roughly from -2^31 to 2^31) yet Matlab's implementation is returning unsigned longs as the internal state (0 to 2^32). Is there a way I can mediate the two to run the same seeds on two different programs (i.e. R which uses signed long and Matlab using unsigned)?
Thanks very much, -Clinton
Answers (2)
Walter Roberson
on 15 Nov 2012
I do not know anything about that random generator, but you could experiment with using
typecast(TheUnsignedValue, 'int32')
this would re-interpret the bits as signed.
Peter Perkins
on 16 Nov 2012
1 vote
The original paper defines the internal state of MRG32k3a as unsigned ints, and the public methods in (what I think is) the reference implementation present the seeds as unsigned ints (although it uses doubles internally for performance reasons). You're right, though, that other implementations use signed ints. However, note that the doc for SSJ describes the constraints on the seed vector as
"the first 3 values of the seed must all be less than m1 = 4294967087, and not all 0; and the last 3 values must all be less than m2 = 4294944443, and not all 0"
My guess would be that, as Walter suggests, you can use TYPECAST, although I can't say for sure what other implementations do internally.
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!