function [ X, S ] = myrand( M, N, S )
%MYRAND Implements the Wichman-Hill generator to sample from U(0,1).
% The parameters M and N specify the size of the matrix which is
% returned and S is the seed, i.e., R = MYRAND(M,N,S) returns an
% M-by-N matrix of independent pseudo-random numbers, which are uniformly
% distributed on (0,1) and the generator is seeded with S (a 3-element
% vector). The parameters of the generator used are a_1 = 171, a_2 = 170,
% a_3 = 172 and m_1 = 30269, m_2 = 30307, m_3 = 30323.
a = [171, 170, 172];
m = [30269, 30307, 30323];
X = zeros(M, N);
for i=1:(M*N)
S = mod(a .* S, m);
X(i) = mod(sum(S ./ m), 1);
end
end