Is randperm() consistent under different hardware platform, OS, MATLAB versions?

I use randperm() to generate sets of numbers repeatly using a for loop. I always make sure I keep the RandStream consistent over different running environment by using such as,
RandStream.setDefaultStream(RandStream('mt19937ar','seed',1); or RandStream.getDefaultStream();
Recently, I've notice that sometimes I get different randomization sequences across the sequential randperm sets, although I was using an identical seed. The only difference was 1) Physical processor (I was using number of heterogeneous cluster nodes)
Should I get the same sequences across different processors?

回答 (3 件)

Walter Roberson
Walter Roberson 2012 年 9 月 26 日

0 投票

Exactly which point you seed at could make a difference. When you use multiprocessing operations, the different tasks are seeded differently, so you would need to seed inside the parallel operation.
Matt Fig
Matt Fig 2012 年 9 月 27 日
編集済み: Matt Fig 2012 年 9 月 27 日
Let's test it out!
What do you get? Post in a comment...
% r2011b, Windows 7, 64bit maxNumCompThreads=4
rng(678)
randperm(10)
randperm(10)
ans =
6 5 9 10 1 4 2 3 8 7
ans =
7 4 3 6 8 5 1 2 9 10
Now, on the same system:
% r2007b, Windows 7, 64bit maxNumCompThreads=1
rand('twister',678)
randperm(10) % Same as above...
randperm(10) % Same as above...

6 件のコメント

Walter Roberson
Walter Roberson 2012 年 9 月 27 日
I get the same pair of results on R2012a, Mac OS-X Lion, 64 bit
Matt Fig
Matt Fig 2012 年 9 月 27 日
Now we just need a linux person to chime int!
Daniel Shub
Daniel Shub 2012 年 9 月 27 日
I thought Walter was a Linux person... Same in Linux (R2011a, Arch, 64-bit).
Matt Fig
Matt Fig 2012 年 9 月 27 日
Is Mac OS a linux thing? I don't know much about it.
Daniel Shub
Daniel Shub 2012 年 9 月 27 日
No, Mac and Linux are different. I just thought Walter used Linux and not a Mac.
Walter Roberson
Walter Roberson 2012 年 9 月 28 日
I was on Linux where I used to work.

サインインしてコメントする。

Peter Perkins
Peter Perkins 2012 年 9 月 28 日

0 投票

John, there is no difference in the random number generators between different hardware.
You seem to be saying that this was a distributed environment. Without knowing more, it's hard to say anything concrete, but you have to be careful about your random stream initialization on the workers. Especially if this is a parfor loop, since the way the iterations get doled out is unpredictable.

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

2012 年 9 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by