function r = halton_base ( i, m, b )

%*****************************************************************************80
%
%% HALTON_BASE computes an element of a Halton sequence with user bases.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    11 August 2016
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    John Halton,
%    On the efficiency of certain quasi-random sequences of points
%    in evaluating multi-dimensional integrals,
%    Numerische Mathematik,
%    Volume 2, pages 84-90, 1960.
%
%  Parameters:
%
%    Input, integer I, the index of the element of the sequence.
%    0 <= I.
%
%    Input, integer M, the spatial dimension.
%
%    Input, integer B(M), the bases to use for each dimension.
%
%    Output, real R(M), the element of the sequence with index I.
%
  b = b(:);

  i = abs ( floor ( i ) );

  t(1:m,1) = i;
%
%  Carry out the computation.
%
  b_inv(1:m,1) = 1.0 ./ b(1:m,1);

  r = zeros ( m, 1 );

  while ( any ( t ~= 0 ) )
    for j = 1 : m
      d = mod ( t(j), b(j) );
      r(j) = r(j) + d * b_inv(j);
      b_inv(j) = b_inv(j) / b(j);
      t(j) = floor ( t(j) / b(j) );
    end
  end

  return
end

