function iarray = genprm ( iarray, n )

%*****************************************************************************80
%
%% genprm() generates and applies a random permutation to an array.
%
%  Discussion:
%
%    To see the permutation explicitly, let the input array be
%    1, 2, ..., N.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    31 March 2013
%
%  Author:
%
%    Original FORTRAN77 version by Barry Brown, James Lovato.
%    MATLAB version by John Burkardt.
%
%  Input:
%
%    integer IARRAY(N), an array to be permuted.
%
%    integer N, the number of entries in the array.
%
%  Output:
%
%    integer IARRAY(N), the permuted array.
%
  for i = 1 : n
    iwhich = ignuin ( i, n );
    itmp = iarray(iwhich);
    iarray(iwhich) = iarray(i);
    iarray(i) = itmp;
  end

  return
end
