dtlcg
Simple linear congruential random number generator.
This group of functions provides deterministic pseudo-random number generation for 32-bit values. It is intended for lightweight use in tests, simulations, and embedded utilities. It is designed to be small and predictable.
Mini-guide
- Initialize the generator state explicitly by calling the seed function before use.
- Generate successive values by calling the next function on the same state instance.
- Derive bounded values by using the range function with an explicit minimum and maximum.
- Maintain one state structure per independent random sequence.
- Avoid using the generator for cryptographic or security-sensitive purposes.
Example
dtlcg32_t rng;
dtlcg32_seed(&rng, 1234);
uint32_t v1 = dtlcg32_next(&rng);
uint32_t v2 = dtlcg32_next(&rng);
int32_t r = dtlcg32_next_range(&rng, 0, 10);
Data structures
dtlcg32_t
Holds the internal state for a 32-bit linear congruential generator.
Members:
uint32_t stateInternal generator state.
Functions
dtlcg32_next
Advances the generator state and produces the next 32-bit value.
Params:
dtlcg32_t* lcgPointer to the generator state.
Return: uint32_t The next pseudo-random value.
dtlcg32_next_range
Advances the generator state and produces a bounded signed integer value.
Params:
dtlcg32_t* lcgPointer to the generator state.
int32_t minLower bound of the output range.
int32_t maxUpper bound of the output range.
Return: int32_t A pseudo-random value in the specified range.
dtlcg32_seed
Initializes the generator state with a fixed seed value.
Params:
dtlcg32_t* lcgPointer to the generator state.
uint32_t seedInitial seed value for the generator.
Return: void No return value.