function r = randmcg ( p, q )

%*****************************************************************************80
%
%% randmcg() evaluates a multiplicative congruential uniform random number generator.
%
%  Discussion:
%
%    Based on the parameters used by MATLAB version 4.
%
%    The statement
%      r = randmcg
%    generates a single uniformly distributed random number.
%
%    The statement
%      r = randmcg(m,n)
%    generates an m-by-n random matrix.
%
%    The statement
%      clear randmcg
%    will cause the generator to reinitialize itself.
%
%    See also RANDGUI, RANDSSP.
%
%  Licensing:
%
%    Copyright 2014 The MathWorks, Inc.
%
%  Author:
%
%    Cleve Moler
%
%  Reference:
%
%    Cleve Moler,
%    Numerical Computing with MATLAB,
%    SIAM, 2004,
%    ISBN13: 978-0-898716-60-3,
%    LC: QA297.M625,
%    ebook: https://www.mathworks.com/moler/chapters.html
%
persistent m a c x
if isempty(x)
   m  = 2^31-1;
   a = 7^5;
   c = 0;
   x = 1;
end

if nargin < 1, p = 1; end
if nargin < 2, q = p; end
r = zeros(p,q);
for k = 1:p*q
   x = rem(a*x + c, m);
   r(k) = x/m;
end
