program testrng
  use rng
  implicit none
  integer, parameter :: double=selected_real_kind(12)
  integer, parameter :: single=selected_real_kind(6)
  type(rng_state) :: state
  integer, dimension(rng_s) :: seed
  real(double) :: x
  real(double),dimension(1234) :: xa
  real(single) :: y
  real(single),dimension(2,3,5) :: ya

  print '(a,a)', 'Test of random number routines, ',&
    'all numbers should match EXACTLY'

  call rng_set_seed(seed,'3.141592653589793238462643383279502')
  call rng_step_seed(seed,23,-95,110)
  print '(a,a)','Seed (2902248648199272781830143864736810): ',&
    rng_print_seed(seed)
  call rng_init(seed,state)
  call rng_number(state,x)
  print '(a,f17.15)','Zeroth number (0.540373998032440): ',x
  call rng_number(state,xa)
  print '(a,f17.15)','1234th number (0.478292786832260): ',xa(1234)
  call rng_step_seed(seed,-23,95,-110)
  print '(a,a)','Seed (3141592653589793238462643383279502): ',&
    rng_print_seed(seed)

  print *

  print '(a)','Examples of rng_set_seed'
  call rng_set_seed(seed)
  print '(a,a)','Seed from current time:     ', rng_print_seed(seed)
  call rng_set_seed(seed,(/1776,07,04,-300,12,0,0,0/))
  print '(a,a)','Seed at specifed time:      ', rng_print_seed(seed)
  call rng_set_seed(seed,123456789)
  print '(a,a)','Seed from an integer:       ', rng_print_seed(seed)
  call rng_set_seed(seed,'123456789')
  print '(a,a)','Seed from a decimal string: ', rng_print_seed(seed)
  call rng_set_seed(seed,'ABCD1234')
  print '(a,a)','Seed from string ABCD1234:  ', rng_print_seed(seed)

  print *

  call rng_init(seed,state)
  call rng_number(state,y)
  print '(a,f8.6)','Single precision random number: ',y

  ya=0
  call rng_number(state,ya(2,:,::2))
  print '(a,15f6.3)','Random array slice: ', ya(2,:,:)

  call rng_gauss(state,x)
  print '(a,f18.15)','A Gaussian random number: ',x
  stop
end program testrng
