Dear reader
When I run the following simple script the output displayed in the Matlab prompt shows two times the same random sequence while the seed has clearly changed. I'm wondering how this is possible? I know that by replacing rng(state) with rng(15) the seed can also be changed. (I tried it and the sequences are different as expected). However I would like to know why changing the seed directly in the state and then writing the state back, doesn't have the same effect.
Kind regards
Lex
script:
close all clear clc rng('default') state=rng; rng() randn(1,5) state.Seed=15; rng(state); rng() randn(1,5)
Output:
ans = Type: 'twister' Seed: 0 State: [625x1 uint32] ans = 0.5377 1.8339 -2.2588 0.8622 0.3188 ans = Type: 'twister' Seed: 15 State: [625x1 uint32] ans = 0.5377 1.8339 -2.2588 0.8622 0.3188
Matlab version: R2011b (7.13.0.564) 64-bit (win64)
Best Answer