function mono ( )

%*****************************************************************************80
%
%% MONO computes the expected monotone length of a random sequence.
%
%  Discussion:
%
%    Generate a sequence of random values until the next value is not larger
%    than the previous one.   Estimate the expected average length of
%    this sequence.
%
%  Modified:
%
%    23 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Digital Dice: Computational Solutions to Practical Probability Problems,
%    Princeton, 2008,
%    ISBN: 978-0-691-15821-1.
%    
  fprintf ( 1, '\n' );
  fprintf ( 1, 'MONO:\n' );
  fprintf ( 1, '  Expected value of the number of random numbers that\n' );
  fprintf ( 1, '  can be generated, which are monotone increasing.\n' );

  sum = 0;
  for k = 1 : 1000000
    L = 0;
    max = 0;
    stop = 0;
    while ( stop == 0 )
      x = rand ( );
      if ( x > max )
        max = x;
      else
        stop = 1;
      end
      L = L + 1;
    end
    sum = sum + L;
  end
  sum = sum / 1000000;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Extimated expected length = %g\n', sum );
  fprintf ( 1, '  Expected value is %g.\n', exp ( 1.0 ) );

  return
end
