rand(n,1)
古いコメントを表示
I gave an exam and figured I'd use rand in a few places to make sure there was no cheating. For question #2 on the exam, I specifically had 6 students solve the equation Ax=b with A=[0 -1 0 -1; -1 0 1 -2; 1 -1 0 1; 0 1 1 0]; and b=rand(4,1). I received exactly 3 different b-vectors from 3 pairs of students that don't talk with each other. In trying to understand the "chances" of this, I found
which says
"All the random number functions, rand, randn, randi, and randperm, draw values from a shared random number generator. Every time you start MATLAB®, the generator resets itself to the same state. Therefore, a command such as rand(2,2) returns the same result any time you execute it immediately following startup. Also, any script or function that calls the random number functions returns the same result whenever you restart."
I understand that when I open up and run matlab that it will reset the generator to the same state but is it obvious from this or other documentation that this should happen for pairs of people (with different releases and platforms)? A subsequent question had them use rand(3,3) and 6 different matrices were submitted.
3 件のコメント
John D'Errico
2019 年 10 月 29 日
Different platforms should not be an issue. Two platforms with the same release should generate the same sequence based on the same startng seed. The default starting seed for these tools is based on the Mersenne twistor algorithm, with a starting seed of 0. And that will be the same across platform. It will even be true for various recent releases, at least since those tools were introduced in their current form. So, without checking, I'd bet that R2019b, R2018a, etc, all give the same sequence by default.
So, if the first thing a pair of students did when they started MATLAB was to call rand, then they will indeed get the same results.
I'm not sure you can use this as strongly affirmative evidence of collusion between students. Any evidence is evidence, but the strength may be weak.
In the future, if you want to ensure they are doing their own work, requiring a call to rng('shuffle') may be a good idea.
Walter Roberson
2019 年 10 月 29 日
Some older releases used different random number generators.
John D'Errico
2019 年 10 月 29 日
Yes. There would be some release date beyond which it would be an issue.
回答 (1 件)
Ajay Pattassery
2019 年 10 月 31 日
0 投票
It is difficult to reason why exactly three different pairs generated from the above information.
Atleast from MATLAB R2012a onwards when you open MATLAB, the result of the rand function is the same.
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!