function r = eml_rand(cmd,varargin)
%MATLAB Code Generation Private Function

%   USAGE:
%   current_method = eml_rand('method')
%   old_method = eml_rand('method',new_method)
%   r = eml_rand('generate_normal',<size arguments>,<class>)
%   r = eml_rand('generate_uniform',<size arguments>,<class>)

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

coder.internal.prefer_const(cmd,varargin);
V4 = eml_rand_str2id('mcg16807');
V5NORMAL = eml_rand_str2id('shr3cong');
TWISTER = eml_rand_str2id('mt19937ar');
persistent method
if isempty(method)
    method = TWISTER;
end
if strcmp(cmd,'method')
    r = method;
    if nargin > 1
        method = varargin{1};
    end
    return
end
% Preallocate return value.
if nargin > 1 && ischar(varargin{end})
    if coder.const(strcmp(cmd,'generate_normal'))
        eml_invariant(coder.internal.isFloatClass(varargin{end}), ...
            'MATLAB:randn:invalidOutputType', ...
            'IfNotConst','Fail');
    else
        eml_invariant(coder.internal.isFloatClass(varargin{end}), ...
            'MATLAB:rand:invalidOutputType', ...
            'IfNotConst','Fail');
    end
end
if method == V4
    r = eml_rand_mcg16807_stateful(cmd,varargin{:});
elseif method == V5NORMAL
    r = eml_rand_shr3cong_stateful(cmd,varargin{:});
else % if method == TWISTER
    r = eml_rand_mt19937ar_stateful(cmd,varargin{:});
end
