MATLAB: Seed choise in rng.

MATLABrandom number generatorrngseed

Dear reader,
I want to generate random numbers that are repeatable. To this end I use rng(seed).
Is there any rule on how to select the seed? I mean that I could take repeatable numbers using either seed=77, or seed=123123, but I do not know the reason why to select/reject the one or the other value of seed.
I have also an additional question, related to rng.
In all the examples I have seen with rng, only the rand, randi, and randn are used. Can I use instead exprnd?
Thank you in advance.

Best Answer

The choice of seed value is arbitrary. It's not like a seed of 42 would make the array of pseudorandom numbers generated by the next call to rand / randn / randi / randperm "more random" or "less random" than a seed of 43. If you set the seed using rng to the same value and call the same random number function to generate the same number of pseudorandom numbers you'll get the same set of numbers.
rng(42)
x1 = rand(1, 10);
rng(42)
x2 = rand(1, 10);
isequal(x1, x2) % true
For your additional question, if exprnd calls rand, randn, randi, and/or randperm in the same order and with the same inputs each time you call it and doesn't change the random number stream inside itself (by calling rng or by explicitly creating a random number stream for its own use) yes, you can get reproducible results from exprnd. Looking at the exprnd code, it calls rand and performs a few computations using the numbers returned from that call. It doesn't change the random number stream inside.
rng(12345)
x1 = exprnd(0.5, 1, 10);
rng(12345)
x2 = exprnd(0.5, 1, 10);
isequal(x1, x2)
Note the advice at the end of the "Specify the Seed" section on this documentation page. This can insulate you from legacy code that uses discouraged syntaxes of rand and randn.