function r = eml_rand_shr3cong_stateful(method,varargin)
%MATLAB Code Generation Private Function

%   Copyright 2005-2015 The MathWorks, Inc.
%#codegen

persistent state
if isempty(state)
    state = coder.const(eml_rand_shr3cong('default_state'));
end
if coder.const(strcmp(method,'generate_uniform'))
    coder.internal.prefer_const(varargin);
    r = coder.nullcopy(zeros(varargin{:}));
    for k = 1:numel(r)
        [state,r(k)] = eml_rand_shr3cong('generate_uniform',state,class(r));
    end
elseif coder.const(strcmp(method,'generate_normal'))
    coder.internal.prefer_const(varargin);
    r = coder.nullcopy(zeros(varargin{:}));
    for k = 1:numel(r)
        [state,r(k)] = eml_rand_shr3cong('generate_normal',state);
    end
elseif coder.const(strcmp(method,'default'))
    state = eml_rand_shr3cong('default_state');
elseif coder.const(strcmp(method,'seed'))
    state = eml_rand_shr3cong('seed_to_state',state,varargin{1});
elseif coder.const(strcmp(method,'state'))
    r = state;
    if nargin > 1
        eml_rand_shr3cong('assert_valid_state',varargin{1});
        state = varargin{1};
    end
else
    eml_assert(false,['Unknown method: ',method]);
end
