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