function [x] = rng15(n,x0)

a = int32(219) ;     % Multiplicative constant
c = int32(7) ;     % Additie constant
m = int32(2^15) ;    % Modulus
persistent s       % State

if nargin > 1,
   % If x0 is given, we use it as the seed
   s = int32(x0) ;
elseif isempty(s),
   % If no state is set, we use a hardcoded one.
   s = 11 
end 

% Start with an empty array
x = [] ;

% Iterate n times to generate an array of random numbers
for i=1:n,
   s = mod(a*s + c, m ) ;
   x = [ x s ] ;
end
 
