    PROGRAM nag_rand_discrete_ex02

      ! Example Program Text for nag_rand_discrete
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_out
      USE nag_rand_discrete, ONLY : nag_rand_seed_set, nag_rand_hypergeo, &
       nag_rand_ref_vec, nag_deallocate, nag_seed_wp => nag_seed_dp, &
       nag_ref_vec_wp => nag_ref_vec_dp
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Parameters ..
      INTEGER, PARAMETER :: r = 5
      CHARACTER (*), PARAMETER :: fmt = '(/1x,a/(1X, 8i5))'
      ! .. Local Scalars ..
      INTEGER :: k, l, m, n
      TYPE (nag_ref_vec_wp) :: ref
      TYPE (nag_seed_wp) :: seed
      ! .. Local Arrays ..
      INTEGER :: iv(r)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) &
       'Example Program Results for nag_rand_discrete_ex02'

      ! Generating random integers in one step

      k = 0

      CALL nag_rand_seed_set(seed,k)

      l = 100
      m = 50
      n = 1000

      CALL nag_rand_hypergeo(l,m,n,iv,seed)

      WRITE (nag_std_out,fmt) &
       'Hypergeometric distribution : l=100,m=50,n=1000; one step approach', &
       iv

      ! Generating random integers in two steps

      CALL nag_rand_hypergeo(l,m,n,ref) ! create reference vector

      k = 0

      CALL nag_rand_seed_set(seed,k)

      iv = nag_rand_ref_vec(seed,ref,r)

      WRITE (nag_std_out,fmt) &
       'Hypergeometric distribution: l=100,m=50,n=1000; two steps approach', &
       iv

      CALL nag_deallocate(ref)     ! Free structure allocated by NAG fl90

    END PROGRAM nag_rand_discrete_ex02
