%
% function U = rank_1(Qdim,N,Nr,rans)
%
% rank-1 lattice rule QMC point generator
%
% inputs: Qdim = dimension of QMC points
%         N    = number of QMC points
%         Nr   = number of randomisations
%         rans = randomisation inputs (Qdim,Nr)
%

function U = rank_1(Qdim,N,Nr,rans)

persistent z

if nargin==0
  load z_d4096_m15_gf1
  return;
end

%
% version 1: interleaved family sets
%

% U = z(1:Qdim) * reshape(repmat(1:N,Nr,1),1,Nr*N) / N;
% U = rem(U+repmat(rans,1,N),1);

%
% version 2: grouped into family sets -- more compatible
%            with MATLAB scrambled Sobol point generation
%

U    = repmat(z(1:Qdim)*(1:N)/N, 1,Nr);
rans = reshape(repmat(rans,N,1),Qdim,N*Nr);
U    = rem(U+rans,1);

end

