MATLAB: How to explain the random functions to the professor

distribution functionrand

ok.. so the works I do usually do not require using Matlab, but in one case, I had to generate random values for several distributions such as normal, lognormal, weibull…
I am sure all the random value generating distribution function work the same way.
I am to generate 3 random arrays. For example:
A=normrnd(3,10,[1,5])
B=normrnd(30,100,[1,5])
C=normrnd(300,1000,[1,5])
So… i get 1×5 vector named A, B, and C.
Everything going well and then my professor, who does not know anything about Matlab or coding but clames himself as an expert, heard something from someone about the random function, and now is tackling me with stuff that he can't explain. The sad part is his words might have a point since he probabily did hear this from someone who knows Matlab.
  1. He said he does not know how matlab generates random values from rand functions, but the random function picking all 5 values at once([1,5] for the above example) is different from picking 1 value each for 5 times.
  2. Also, it will be different from picking one value each from A,B,C for 5 times compared to picking all 5 from A, then moving on to B, then C. Now this part does not make sense, since I know matlab finishes generating vector for A and goes to B and C.
For the first part, in other words, he is saying if the random function picks one value each for 5 times, the generation of random value is affected by the previously generated value. I asked him if he is talking about permutation/combination situation, but he said it's more complicated than that.
This professor… this is the guy who says Minitab generates random function in 'right way', not because he knows the generation algorithm and process, but because this program is strictly made for statistical analysis, unlike the Matlab. I told him I will generate the values from the Minitab as he likes then use the values in Matlab, but he said 'That is not the researcher's way of doing things'…
I tried to look at the documents related to rand functions, but honestly I cannot understand.
Can anyone help me convince this professor so I can just use these functions?

Best Answer

I wonder if your professor needs to learn a few things. For starters, that Minitab is not doing anything any better than is MATLAB. The values that Minitab generates are not truly random either. Minitab uses a generator that employs a starting seed, that then forms a pseudo-random sequence.
Each number is never going to be truly random in any such sequence. Computer random number generators use algorithms for the numbers, so each number from the sequence has properties that are as close to truly random as mathematicians can make them. There are limits to what you can do.
First, lets look at MATLAB. There is NO difference between 5 successive calls to rand, instead of rand(1,5). The way to show that is to make two sets of calls preceded by a reset of the random state to the default.
rng('default')
>> rand(1,5)
ans =
0.81472 0.90579 0.12699 0.91338 0.63236
>> rng('default')
>> rand(1)
ans =
0.81472
>> rand(1)
ans =
0.90579
>> rand(1)
ans =
0.12699
>> rand(1)
ans =
0.91338
>> rand(1)
ans =
0.63236
You can learn about the methods used in MATAB to generate a pseudo-random seuence, in
doc rng
There you will see various random schemes that are offered. In R2019a, you will see the statement:
" In this release, the default settings are the Mersenne Twister with seed 0."
You can choose the scheme employed, IF your professor thinks one of the alternatives is better than the default.
As for the second comment, about order that you choose from A,B,C, etc. is meaningless. The elements of such a pseudo-random sequence are independent. So the "order" is irrelevant.
However, if you did this in Minitab too? You would see similar behavior. I don't have Minitab. But I can read the documentation. For example, here:
In there, we se that Minitab also uses a random seed. In fact, this is a good behavior for simulations. For some simulations, you WANT to be able to have a REPRODUCIBLE random sequence, which might seem to be a bit of an incongruity. Such behavior can be a good thing, as long as the sequence itself has the properties you want to see in a pseudo-random sequence.
Yes, you can apparently obtain truly random numbers from some sources. But Minitab does not make any such claim. The use of a random seed tells us that the sequence it provides is no better than that provided by MATLAB.
If we look online for true random numbers, I find this as an example:
In there, they claim:
"RANDOM.ORG offers true random numbers to anyone on the Internet. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs."
But what we don't know is how those random numbers behave. Are they TRULY UNIFORMLY random? For example, you can have a random sequence that is not uniform either. In the end, you can trust what they claim, or you can spend the time needed to devise and perform truly extensive tests. Oh well. Take it for what it is worth.
If you are looking for a sequence that is not quite so predictable? Well, you can do a shuffle, AT THE BEGINNING!
rng('shuffle') seeds the random number generator based on the current time.
Do NOT try to shuffle the seed before each call! This is a mistake made by some people, who think they can get a truly random seqeunce by shuffling before every call to rand. That is actually a mistake, as it may result in a non-random sequence.