function r = randmc(p,q)

% Multiplicative congruential uniform random number generator.
% Based on the parameters used by MATLAB version 4.
%
% r = randmc
% generates a single random number.
%
% r = randmc(m,n)
% generates an m-by-n random matrix.
% 
% clear randmc
% reinitializes the generator.
%
% Seeds are set by editing this file.
%
%  See also RANDEX, RANDSSL.

persistent a c m x

if isempty(x)
   a = 7^5;
   c = 0;
   m  = 2^31-1;
   x = 1;
end

if nargin < 1, p = 1; end

if nargin < 2, q = p; end

r = zeros(p,q); %Preallocate memory
for k = 1:p*q
   x = rem(a*x + c, m);
   r(k) = x/m;
end