public function random_hex(length) result(out)
NAME
random_hex(3f) - [M_random] create a string representing a random
hexadecimal value of specified length
(LICENSE:MIT)
SYNOPSIS
function random_hex(chars,length) result(out)
character(len=*),intent(in) :: chars
integer,intent(in) :: length
character(len=:),allocatable :: out
DESCRIPTION
Generate a random string representing a hexadecimal value of a given length
OPTIONS
length number of characters to place in output string
RESULT
out string of LENGTH characters randomly filled with characters
representing a hexadecimal value
EXAMPLE
Sample program:
program demo_random_hex
use M_random, only : random_hex, init_random_seed_by_dat
character(len=64) :: hexstring
! use date and time to create a seed for calling random_seed(3f)
call init_random_seed_by_dat()
! write random hexadecimal value for use
! as something like an X11 authorization key
hexstring=random_hex(len(hexstring))
write(*,'(a)')hexstring
end program demo_random_hex
Results
2363a3589736e23be0137ec7ebc9d74297a963f27958a176daea3dd850ed8487
AUTHOR
LICENSE
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
integer,
|
intent(in) |
|
|
:: |
length |
|
Return Value
character(len=:), allocatable
Source Code
function random_hex(length) result(out)
! ident_2="@(#) M_random random_hex(3f) create random hexadecimal string of specified length"
integer,intent(in) :: length
character(len=:),allocatable :: out
out=random_string('0123456789abcdef',length)
end function random_hex