dexran(3f) - [M_datapac:RANDOM] generate double exponential
random numbers
subroutine dexran(N,Istart,X)
integer,intent(in) :: N
integer,intent(inout) :: Istart
real(kind=wp) :: X(:)
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))
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.
X A REAL vector (of dimension at least N) into which
the generated random sample will be placed.
Sample program:
program demo_dexran
use M_datapac, only : dexran
implicit none
! call dexran(x,y)
end program demo_dexran
Results:
The original DATAPAC library was written by James Filliben of the
Statistical Engineering Division, National Institute of Standards
and Technology.
John Urban, 2022.05.31
CC0-1.0
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | N | |||
integer, | intent(inout) | :: | Istart | |||
real(kind=wp) | :: | X(:) |
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