function p = cube_surface_sample ( n )

%*****************************************************************************80
%
%% cube_surface_sample randomly selects points on the surface of a cube.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 January 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of points to sample.
%
%  Output:
%
%    real P(N,3), N points selected uniformly at random from
%    the surface of the unit cube.
%
  p = rand ( n, 3 );
%
%  I chooses whether X or Y or Z will be on the surface of the cube.
%
  i = randi ( [ 0, 2 ], 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

