dexran Subroutine

public subroutine dexran(N, Istart, X)

NAME

dexran(3f) - [M_datapac:RANDOM] generate double exponential
random numbers

SYNOPSIS

   subroutine dexran(N,Istart,X)

    integer,intent(in)    :: N
    integer,intent(inout) :: Istart
    real(kind=wp)         :: X(:)

DESCRIPTION

DEXRAN(3f) generates a random sample of size n from the double
exponential (Laplace) distribution with mean = 0 and standard deviation
= sqrt(2).

This distribution is defined for all X and has the probability
density function

    f(X) = 0.5*exp(-abs(X))

INPUT ARGUMENTS

N        The desired integer number of random numbers to be generated.

ISTART   An integer flag code which (if set to 0) will start the
         generator over and hence produce the same random sample
         over and over again upon successive calls to this subroutine
         within a run; or (if set to some integer value not equal to
         0, like, say, 1) will allow the generator to continue from
         where it stopped and hence produce different random samples
         upon successive calls to this subroutine within a run.

OUTPUT ARGUMENTS

X     A REAL vector (of dimension at least N) into which
      the generated random sample will be placed.

EXAMPLES

Sample program:

program demo_dexran
use M_datapac, only : dexran
implicit none
! call dexran(x,y)
end program demo_dexran

Results:

AUTHOR

The original DATAPAC library was written by James Filliben of the
Statistical Engineering Division, National Institute of Standards
and Technology.

MAINTAINER

John Urban, 2022.05.31

LICENSE

CC0-1.0

REFERENCES

  • Tocher, The Art of Simulation, 1963, pages 14-15.
  • Hammersley and Handscomb, Monte Carlo Methods, 1964, page 36.
  • Filliben, Simple and Robust Linear Estimation of the Location Parameter of a Symmetric Distribution (Unpublished PH.D. dissertation, Princeton University), 1969, page 231.
  • Filliben, ‘The percent point function’, (Unpublished manuscript), 1970, pages 28-31.
  • Johnson and Kotz, Continuous Univariate Distributions–2, 1970, pages 22-36.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: N
integer, intent(inout) :: Istart
real(kind=wp) :: X(:)

Source Code

subroutine dexran(N,Istart,X)
integer,intent(in)    :: N
integer,intent(inout) :: Istart
real(kind=wp)         :: X(:)

integer               :: i
real(kind=wp)         :: q
!---------------------------------------------------------------------
!     CHECK THE INPUT ARGUMENTS FOR ERRORS
!
   if ( N<1 ) then
      write (G_io,99001)
      99001 format (' ***** FATAL ERROR--THE FIRST INPUT ARGUMENT TO DEXRAN(3f) IS NON-POSITIVE *****')
      write (G_io,99002) N
      99002 format (' ','***** THE VALUE OF THE ARGUMENT IS ',I0,' *****')
   else
      !
      !  GENERATE N UNIFORM (0,1) RANDOM NUMBERS;
      !
      call uniran(N,Istart,X)
      !
      !  GENERATE N DOUBLE EXPONENTIAL RANDOM NUMBERS
      !  USING THE PERCENT POINT FUNCTION TRANSFORMATION METHOD.
      !
      do i = 1 , N
         q = X(i)
         if ( q<=0.5_wp ) X(i) = log(2.0_wp*q)
         if ( q>0.5_wp ) X(i) = -log(2.0_wp*(1.0-q))
      enddo
   endif

end subroutine dexran