function [ x, seed ] = random_permutation ( n, x, seed )

%*****************************************************************************80
%
%% RANDOM_PERMUTATION applies a random permutation to an array.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license. 
%
%  Modified:
%
%    21 February 2016
%
%  Author:
%
%    Original C version by Warren Smith.
%    This MATLAB version by John Burkardt.
%
%  Parameters:
%
%    Input, integer N, indicates the size of X.
%
%    Input/output, real X(0:N+1).  On output, entries 
%    X(1) through X(N) have been randomly permuted.
%
%    Input/output, integer SEED, a seed for the random 
%    number generator.
%
  for i = 1 : n - 1

    [ j, seed ] = i4_uniform_ab ( i, n, seed );

    t      = x(i+1);
    x(i+1) = x(j+1);
    x(j+1) = t;
     
  end

  return
end

