function correlation ( j  )

#*****************************************************************************80
#
## correlation() plots the scatter diagram of (X(I), X(I+J)).
#
#  Discussion:
#
#    Plotting X(I) versus X(I+J) can exhibit patterns if there is
#    correlation in the data.  If not, the scatter plot will be patternless.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    08 February 2023
#
#  Author:
#
#    Original MATLAB version by Paul Nahin.
#    This version by John Burkardt.
#
#  Reference:
#
#    Paul Nahin,
#    Dueling Idiots and Other Probability Puzzlers,
#    Princeton, 2012,
#    ISBN: 978-0691155005.
#
#  Input:
#
#    integer J, the offset to use in the correlation.
#
  print ( '' )
  print ( 'correlation():' )
  print ( '  Plotting X(I) versus X(I+J) can exhibit patterns if there is' )
  print ( '  correlation in the data.  If not, the scatter plot will be patternless.' )

  stop = 1000 + j
  data = zeros ( 1, stop )
  for i = 1 : stop
    data(i) = rand ( )
  end

  for i = 1 : 1000
    x(i) = data(i)
    y(i) = data(i+j)
  end
#
#  Graphics.
#
  clf ( )
  plot ( x, y, '.' )
  xlabel ( 'j = 9' )
  title('1000-Point Scatter Diagram for MATLAB 5.2 Uniform Random Number Generator')
  filename = 'correlation.png'
  plt.savefig ( filename )
  print ( '  Graphics saved as "' + filename + '"' )
  plt.close ( )

  return
end
