pf_random_int_at Interface

public interface pf_random_int_at

A uniform integer in [lo, hi], exactly unbiased: value draw (default 1) of stream i.

i, lo and hi share one kind -- integer(int32) or integer(int64) -- and the result follows it; seed and draw are always integer(int64). Swaps internally when lo > hi, so the function is total. Every width is exact, including the widest: no modulo bias, at any range, on either side of the fork.


Module Procedures

private pure elemental function pf_random_int_at_i32(seed, i, lo, hi, draw) result(r)

pf_random_int_at for integer(int32) stream index and bounds.

The result is inside [min(lo,hi), max(lo,hi)] by construction, so narrowing the int64 worker's answer back to int32 is exact and cannot overflow.

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(in) :: seed

the stream family's seed

integer(kind=int32), intent(in) :: i

stream index; sign-extends, so any value is valid

integer(kind=int32), intent(in) :: lo

one end of the closed range

integer(kind=int32), intent(in) :: hi

the other end; lo > hi is swapped, not an error

integer(kind=int64), intent(in), optional :: draw

1-based value index; absent means 1

Return Value integer(kind=int32)

a uniform integer in [min(lo,hi), max(lo,hi)]

private pure elemental function pf_random_int_at_i64(seed, i, lo, hi, draw) result(r)

pf_random_int_at for integer(int64) stream index and bounds.

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(in) :: seed

the stream family's seed

integer(kind=int64), intent(in) :: i

stream index; every value is valid

integer(kind=int64), intent(in) :: lo

one end of the closed range

integer(kind=int64), intent(in) :: hi

the other end; lo > hi is swapped, not an error

integer(kind=int64), intent(in), optional :: draw

1-based value index; absent means 1

Return Value integer(kind=int64)

a uniform integer in [min(lo,hi), max(lo,hi)]