create_seed_from_single_integer Function

private function create_seed_from_single_integer(initial_seed) result(seed)

Uses

Returns an array of integers to use as a seed to the random number generator given a single integer as input.

Currently we just use the lcg generator to generate a series of values to use for the seed. We could also set the actual random seed from this and then use this to generate a final series of seeds. This is probably not really necessary.

For our mt19937 implementation we just set the seed equal to initial_seed

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: initial_seed

Return Value integer, dimension(:), allocatable


Contents


Source Code

  function create_seed_from_single_integer(initial_seed) result(seed)
    use constants, only: kind_id
    implicit none
    integer, intent(in) :: initial_seed
    integer, dimension(:), allocatable :: seed
    integer :: seed_size, i
    integer(kind = kind_id) :: current

    ! Get the required state size for the seed
    call random_seed(size = seed_size)

    allocate(seed(seed_size))

    ! Use lcg to generate a series of random numbers given
    ! the initial seed
    current = initial_seed
    do i = 1, seed_size
       seed(i) = lcg(current)
       current = seed(i)
    end do
  end function create_seed_from_single_integer