random_string Function

function random_string(chars, length) result(out)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: chars
integer, intent(in) :: length

Return Value character(len=:), allocatable


Contents

Source Code


Variables

Type Visibility Attributes Name Initial
integer, public :: i
integer, public :: ilen
integer, public :: which
real, public :: x

Source Code

function random_string(chars,length) result(out)

!$@(#) M_random::random_string(3f): create random string composed of provided characters of specified length

character(len=*),intent(in)  :: chars
integer,intent(in)           :: length
character(len=:),allocatable :: out
real                         :: x
integer                      :: ilen   ! length of list of characters
integer                      :: which
integer                      :: i
   ilen=len(chars)
   out=''
   if(ilen.gt.0)then
      do i=1,length
         call random_number(x)
         which=nint(real(ilen-1)*x)+1
         out=out//chars(which:which)
      enddo
   endif
end function random_string