Commit bf94bb3d authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Implement clock option of set_dynare_seed

Also improve documentation of set_dynare_seed.

Closes #362
parent f4814175
......@@ -7363,10 +7363,19 @@ array stored in a MATLAB/Octave variable.
@deffn Command set_dynare_seed (@var{INTEGER})
@deffnx Command set_dynare_seed ('default')
@deffnx Command set_dynare_seed ('clock')
@deffnx Command set_dynare_seed ('reset')
@deffnx Command set_dynare_seed ('@var{ALGORITHM}', @var{INTEGER})
Sets the seed used for random number generation.
Sets the seed used for random number generation. It is possible to set
a given integer value, to use a default value, or to use the clock (by
using the latter, one will therefore get different results across
different Dynare runs). The @code{reset} option serves to reset the
seed to the value set by the last @code{set_dynare_seed} command. On
MATLAB 7.8 or above, it is also possible to choose a specific
algorithm for random number generation; accepted values are
@code{mcg16807}, @code{mlfg6331_64}, @code{mrg32k3a}, @code{mt19937ar}
(the default), @code{shr3cong} and @code{swb2712}.
@end deffn
......
......@@ -2,7 +2,7 @@ function set_dynare_seed(a,b)
% Set seeds depending on matlab (octave) version. This routine is called in dynare_config and can be called by the
% user in the mod file.
%
% Copyright (C) 2010-2012 Dynare Team
% Copyright (C) 2010-2013 Dynare Team
%
% This file is part of Dynare.
%
......@@ -48,12 +48,13 @@ if matlab_random_streams% Use new matlab interface.
end
return
end
if ischar(a)
error('set_dynare_seed:: something is wrong in the calling sequence!')
end
if ~ischar(a)
if ~ischar(a) || (ischar(a) && strcmpi(a, 'clock'))
options_.DynareRandomStreams.algo = 'mt19937ar';
options_.DynareRandomStreams.seed = a;
if ischar(a)
options_.DynareRandomStreams.seed = rem(floor(now*24*60*60), 2^32);
else
options_.DynareRandomStreams.seed = a;
end
s = RandStream(options_.DynareRandomStreams.algo,'Seed',options_.DynareRandomStreams.seed);
if matlab_ver_less_than('7.12')
reset(RandStream.setDefaultStream(s));
......@@ -62,6 +63,7 @@ if matlab_random_streams% Use new matlab interface.
end
return
end
error('set_dynare_seed:: something is wrong in the calling sequence!')
elseif nargin==2
if ~ischar(a) || ~( strcmpi(a,'mcg16807') || ...
strcmpi(a,'mlfg6331_64') || ...
......@@ -107,13 +109,17 @@ else% Use old matlab interface.
randn('state',options_.DynareRandomStreams.seed);
return
end
if ~ischar(a) && isint(a)
options_.DynareRandomStreams.seed = a;
if (~ischar(a) && isint(a)) || (ischar(a) && strcmpi(a,'clock'))
if ischar(a)
options_.DynareRandomStreams.seed = floor(now*24*60*60);
else
options_.DynareRandomStreams.seed = a;
end
rand(options_.DynareRandomStreams.algo,options_.DynareRandomStreams.seed);
randn('state',options_.DynareRandomStreams.seed);
else
error('set_dynare_seed:: Something is wrong in the calling sequence!')
return
end
error('set_dynare_seed:: Something is wrong in the calling sequence!')
else
error('set_dynare_seed:: Cannot use more than one input argument with your version of Matlab/Octave!')
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment