odd_random_integer 子程序

public subroutine odd_random_integer(harvest)

返回一个 64 位伪随机整数 harvest,在 64 位类型的奇数范围内均匀分布。(规范

参数

类型 意图可选 属性 名称
integer(kind=int64), intent(out) :: harvest

源代码

    subroutine odd_random_integer( harvest )
!! Version: experimental
!!
!! Returns a 64 bit pseudo random integer, `harvest`, distributed uniformly over
!! the odd integers of the 64 bit kind.
!! ([Specification](../page/specs/stdlib_hash_procedures.html#odd_random_integer-returns-odd-integer))

        integer(int64), intent(out) :: harvest
        real(dp) :: sample(2)
        integer(int32) :: part(2)

        call random_number( sample )
        part = int( floor( sample * 2_int64**32, int64 ) - 2_int64**31, int32 )
        harvest = transfer( part, harvest )
        harvest = ishft( harvest, 1 ) + 1_int64

    end subroutine odd_random_integer