function p = hypercube_surface_sample ( n, d )

%*****************************************************************************80
%
%% hypercube_surface_sample randomly selects points on the surface of a hypercube.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 January 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of points to sample.
%
%    integer D, the spatial dimension.
%
%  Output:
%
%    real P(N,D), N points selected uniformly at random from
%    the surface of the unit hypercube in D dimensions.
%
  p = rand ( n, d );
%
%  I chooses whether X or Y or Z will be on the surface of the cube.
%
  i = randi ( [ 0, d-1 ], n, 1 );
%
%  K indexes P as a vector.
%
  k = ( 1 : n )' + i * n;
%
%  S specifies whether a point will be on the lower (0) or upper (1) surface.
%
  s = randi ( [ 0, 1 ], n, 1 );
%
%  Replace some entries of P by surface values.
%
  p(k) = s;

  return
end

