function x = uniform_on_cube01 ( m, n )
%*****************************************************************************80
%
%% UNIFORM_ON_CUBE01 returns random points on the surface of the unit cube.
%
% Discussion:
%
% The cube is assumed to have center C at the origin, and radius 1.
%
% Any point on the surface of the cube is an M-dimensional vector
% whose entries are between -1 and +1, and for which at least one value
% has norm 1.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 20 April 2013
%
% Author:
%
% John Burkardt
%
% Input:
%
% integer M, the spatial dimension.
% 1 <= M.
%
% integer N, the number of points.
%
% Output:
%
% real X(M,N), the coordinates of N points, chosen uniformly at
% random from the surface of the unit M-cube.
%
%
% Choose random points within the cube of radius 1.
%
x = 2.0 * rand ( m, n ) - 1.0;
%
% For each point, select a coordinate at random, and set it to +1 or -1.
%
i = randi ( [ 1, m ], 1, n );
j = 1 : n;
k = i + ( j - 1 ) * m;
s = 2.0 * randi ( [ 0, 1 ], 1, n ) - 1.0;
x(k) = s;
return
end