pcg32_t Derived Type

type, public :: pcg32_t

PCG-XSH-RR 64/32 generator: 64-bit LCG state with a 32-bit output permutation, plus a per-stream odd increment.


Components

Type Visibility Attributes Name Initial
integer(kind=int64), public :: increment = PCG_DEFAULT_INCREMENT

Stream increment; always odd, which is what makes streams distinct.

integer(kind=int64), public :: state = 0_int64

Explicit 64-bit LCG state (fixed width, not default_int).


Type-Bound Procedures

procedure, public :: next => pcg32_next

  • private function pcg32_next(self) result(r)

    Next 32-bit output, returned as the int32 with the same bit pattern as the reference implementation’s uint32_t result. Roughly half of the returned values are therefore negative; use next_real_dp or next_below if a magnitude is wanted.

    Arguments

    Type IntentOptional Attributes Name
    class(pcg32_t), intent(inout) :: self

    Return Value integer(kind=int32)

procedure, public :: next_u64 => pcg32_next_u64

  • private function pcg32_next_u64(self) result(r)

    Full 64-bit random word built from two consecutive 32-bit outputs; the first output supplies the high half. Fixing the order here is what makes next_real_dp and next_below reproducible for this engine.

    Arguments

    Type IntentOptional Attributes Name
    class(pcg32_t), intent(inout) :: self

    Return Value integer(kind=int64)

procedure, public :: seed => pcg32_seed

  • private subroutine pcg32_seed(self, state, seq)

    Seed the generator, following the reference pcg32_srandom_r: the stream selector is shifted left and forced odd to become the LCG increment, then the state is warmed up, offset by the requested state and warmed up again.

    Arguments

    Type IntentOptional Attributes Name
    class(pcg32_t), intent(inout) :: self
    integer(kind=int64), intent(in) :: state
    integer(kind=int64), intent(in) :: seq

Source Code

   type :: pcg32_t
      !! PCG-XSH-RR 64/32 generator: 64-bit LCG state with a 32-bit output
      !! permutation, plus a per-stream odd increment.
      integer(int64) :: state = 0_int64
         !! Explicit 64-bit LCG state (fixed width, not `default_int`).
      integer(int64) :: increment = PCG_DEFAULT_INCREMENT
         !! Stream increment; always odd, which is what makes streams distinct.
   contains
      procedure :: seed => pcg32_seed
      procedure :: next => pcg32_next
      procedure :: next_u64 => pcg32_next_u64
   end type pcg32_t