2014-04-01 18 views

回答

1

我看到了兩個解決方案,您的問題:

  • 如果你有一個主代碼派生這些工作,把它處理了不同的種子到每個MATLAB過程。這可以像rng(job_number)一樣簡單。

  • 另一種方法是使用feature getpid並基於PID信息初始化種子。

0

一種解決方案是使用該過程獨有的任何數據爲RNG播種。例如,如果所有的MATLAB實例都在同一臺機器上運行,你可以做到以下幾點:

rng('shuffle'); % seed with the current time 
rngState = rng; % current state of rng 

%%% deltaSeed can be any data unique to the process, 
%%% including position in the process queue 
deltaSeed = uint32(feature('getpid')); 

seed = rngState.Seed + deltaSeed; 
rng(seed); % set the rng to use the modified seed 

這將當前時間結合與MATLAB實例的進程ID生成種子。

+0

請注意,如果在'now'遞增1時在午夜附近使用該選項,則該選項可能會很脆弱。另外,種子,至少對於默認的隨機數發生器,應該是'uint32'。 – horchler

+0

好點;我編輯了答案。 – Isaac

相關問題