% init_rand_seed: initialize random number generation by specific seed to ensure repeatability of experiments seed = init_rand_seed(seed) seed = int, seed for initialization of rand and randn default 42 if seed = 0 rand is initialized by timestamp Susane Wenzel 09/16 wenzel@igg.uni-bonn.de
0001 %% init_rand_seed: initialize random number generation by specific seed 0002 % to ensure repeatability of experiments 0003 % 0004 % seed = init_rand_seed(seed) 0005 % seed = int, seed for initialization of rand and randn 0006 % default 42 0007 % if seed = 0 rand is initialized by timestamp 0008 % 0009 % Susane Wenzel 09/16 0010 % wenzel@igg.uni-bonn.de 0011 0012 function seed = init_rand_seed(seed) 0013 0014 if nargin<1 0015 seed = 42; 0016 end 0017 if seed == 0 0018 seed = round( sum(10000*clock) ); 0019 end; 0020 0021 disp(['Random seed = ', num2str(seed)]) 0022 0023 if verLessThan('matlab', '15') 0024 rand('state',seed); %#ok<*RAND> 0025 randn('state',seed); 0026 else 0027 rng(seed,'v5uniform'); 0028 end 0029 0030 0031 0032