function cdf = deranged_cdf ( x, a )

%*****************************************************************************80
%
%% deranged_cdf() evaluates the Deranged CDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 January 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer X, the maximum number of items in their correct places.
%    0 <= X <= A.
%
%    integer A, the number of items.
%    1 <= A.
%
%  Output:
%
%    real CDF, the value of the CDF.
%
  if ( x < 0 | a < x )
    cdf = 0.0;
  else
    sum2 = 0;
    for x2 = 0 : x
      cnk = nchoosek ( a, x2 );
      dnmk = deranged_enum ( a-x2 );
      sum2 = sum2 + cnk * dnmk;
    end
    nfact = factorial ( a );
    cdf = sum2 / nfact;
  end

  return
end
