function p = perm_uniform ( n, base )

%*****************************************************************************80
%
%% perm_uniform() selects a random permutation of N objects.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    18 November 2008
%
%  Author:
%
%    John Burkardt.
%
%  Reference:
%
%    A Nijenhuis and H Wilf,
%    Combinatorial Algorithms,
%    Academic Press, 1978, second edition,
%    ISBN 0-12-519260-6.
%
%  Input:
%
%    integer N, the number of objects to be permuted.
%
%    integer BASE, is 0 for a 0-based permutation and 1 for 
%    a 1-based permutation.
%
%  Output:
%
%    integer P(N), a permutation of ( 1, 2, ..., N ), in standard
%    index form.
%
  p = ( 1 : n ) + base - 1;

  for i = 1: n

    j = randi ( [ i, n ], 1 );

    temp = p(i);
    p(i) = p(j);
    p(j) = temp;

  end

  return
end
