What limitations does MATLAB have in pseudo-random sequence generation ?

I am interested in learning about the limitations of the pseudo-random sequences generated by function rand() in terms of statistical independence.
For example if I work with the default rng settings (i.e. Type: 'twister', Seed: 0, State: [625x1 uint32]) and keep calling the function rand(1,1e5) multiple times, will the results eventually repeat ? If yes, then how many function calls are safe to get independent results? Or will the rng change its seed or type automatically to avoid repetitive results?
In the documentation link below it is said that the generated numbers "pass various statistical tests of randomness and independence". I would be very interested in seeing the detailed results of the tests, if possible.
https://www.mathworks.com/help/matlab/math/create-arrays-of-random-numbers.html

 Accepted Answer

According to this page, the period of Mersenne Twister (64 bit version, the default engine used by rand()) method is 2^19937-1

4 Comments

Thank you for your comment. My first concern was to see whether the period is expressed in bits or the 64-bit words. However I now realize that even if it was 2^19937 -1 bits we would still have approximately 2^19931 64-bit words which is roughly 6.7e5999. Do you agree that it is unlikely to reach the end of the Mersenne Twister period in any simulation running on personal computer ?
As for the statistical test sources I found [1] where the MT19937 in table 1 has one of the best performances of all other pseudo-random number generators (at least back in year 2007)
[1] L'ecuyer, Pierre, and Richard Simard. "TestU01: AC library for empirical testing of random number generators." ACM Transactions on Mathematical Software (TOMS) 33.4 (2007): 1-40.
Mersenne Twister is pretty much one of the best pseudo random generator out there. If there is something one should suspect is when MATLAB maps the 64 bits to floating points with 53 bits and the non uniform resolution close to 0s. I actually don't know if there is some study about it or someone has problem with it.
If you were to generate a billion pseudorandom numbers per second, how long would it take you to generate 2^19000 numbers?
totalSeconds = vpa(sym(2)^19000)/1e9
totalSeconds = 
3.7146475666583694944087990552645e+5710
secondsPerYear = seconds(years(1));
totalNumberOfYears = vpa(totalSeconds/secondsPerYear)
totalNumberOfYears = 
1.1771249538480045520266973360623e+5703
So I wouldn't worry.
Instead of total number of years, you might have expressed that as the number of lifetimes of the universe before seeing a repeat. Of course our computers will all be long since turned into dust by then. And even the dust will have been sucked into black holes.

Sign in to comment.

More Answers (0)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Products

Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!