lcg Function

private function lcg(s)

Uses

Simple PRNG derived from gfortran documentation Intended to be used to seed a better PRNG. Probably shouldn't be used directly (hence why this is not public).

Arguments

Type IntentOptional Attributes Name
integer(kind=kind_id), intent(inout) :: s

Return Value integer


Contents

Source Code

lcg

Source Code

  function lcg(s)
    use constants, only: kind_id, kind_is
    implicit none
    integer :: lcg
    integer (kind=kind_id), intent(in out) :: s

    if (kind_id > 0) then
       if (s == 0) then
          s = 104729
       else
          s = mod(s, 4294967296_kind_id)
       end if
       s = mod(s * 279470273_kind_id, 4294967291_kind_id)
       lcg = int(mod(s, int(huge(0), kind_id)), kind(0))
    else
       lcg = mod(16807*int(s,kind_is), 2147483647)
    end if

  end function lcg