MATLAB: Different behaviour of rng() and rand() in parfor-loop

MATLABparallel computingParallel Computing Toolboxparforrandom number generator

Hey folks,
I experienced a different output of the standard function rand() in a parfor-loop although I am using the same seed-value. Example:
>> parfor i = 1:1, rng(123), rand(1,1), end
ans =
0.2751
>> for i = 1:1, rng(123), rand(1,1), end
ans =
0.6965
Is this a bug? I would expect exactly the same output of rand() in parfor.
Thanks & greetings Jonas
————————————————
ps: here are my detailed version information, I use an Intel i7-2600 processor.
—————————————————————————————————-
MATLAB Version: 8.2.0.701 (R2013b)
MATLAB License Number: ••••••
Operating System: Microsoft Windows 7 Version 6.1 (Build 7601: Service Pack 1)
Java Version: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot™ 64-Bit Server VM mixed mode
—————————————————————————————————-
MATLAB Version 8.2 (R2013b)
DIPUM Toolbox Version 1.1.4
DIPUM Toolbox Version 1.1.3
Image Processing Toolbox Version 8.3 (R2013b)
Optimization Toolbox Version 6.4 (R2013b)
Parallel Computing Toolbox Version 6.3 (R2013b)

Best Answer

The client and the workers are set up to use different random generators, so this is expected. This is covered in the documentation. Note that "rng(seed)" changes only the seed but not the underlying generator type.