PCG32

class guppylang.std.random.PCG32[source]

A deterministic 32-bit random number generator using the PCG32 algorithm.

Unlike guppylang.std.qsystem.random.RNG, PCG32 keeps its state in a local Guppy value rather than in platform-global RNG state.

rng = seeded_pcg32(1)
value = rng.next_int()
roll = rng.next_int_bounded(6)
another = rng.next_int()
next_int() int[source]

Advance the generator and return the updated state with a random value.

Returns a signed 32-bit integer, matching the shape of guppylang.std.qsystem.random.RNG.random_int().

next_int_bounded(bound: nat) int[source]

Generate a uniformly random integer in [0, bound).

Uses rejection sampling (pcg32_boundedrand_r from the PCG reference) to avoid the bias introduced by next_int() % bound.

Parameters:

bound – Upper bound (exclusive); must be positive and less than 2**31.

Returns:

A value in [0, bound), matching the shape of guppylang.std.qsystem.random.RNG.random_int_bounded().