1function [state_u,state_n] = get_dynare_random_generator_state()
2% Get state of Matlab/Octave random generator depending on matlab
3% (octave) version.
4% In older versions, Matlab kept one generator for uniformly distributed numbers and
5% one for normally distributed numbers.
6% For backward compatibility, we return two vectors, but, in recent
7% versions of Matlab and in Octave, we return two identical vectors.
8
9% Copyright (C) 2010-2017 Dynare Team
10%
11% This file is part of Dynare.
12%
13% Dynare is free software: you can redistribute it and/or modify
14% it under the terms of the GNU General Public License as published by
15% the Free Software Foundation, either version 3 of the License, or
16% (at your option) any later version.
17%
18% Dynare is distributed in the hope that it will be useful,
19% but WITHOUT ANY WARRANTY; without even the implied warranty of
20% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21% GNU General Public License for more details.
22%
23% You should have received a copy of the GNU General Public License
24% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
25
26matlab_random_streams = ~isoctave;
27
28if matlab_random_streams% Use new matlab interface.
29    if matlab_ver_less_than('7.12')
30        s = RandStream.getDefaultStream();
31    else
32        s = RandStream.getGlobalStream();
33    end
34    if isequal(s.Type,'legacy')
35        state_u = rand('state');
36        state_n = randn('state');
37    else
38        state_u = s.State;
39        state_n = state_u;
40    end
41else% Use old matlab interface.
42    state_u = rand('state');
43    state_n = randn('state');
44end