|
eolib 0.5.0
A core C library for writing applications related to Endless Online
|
The eolib-c RNG module (eolib/rng.h) faithfully emulates the pseudo-random number generator used by the original 32-bit Borland EO game client.
It is a dual-state linear congruential generator with two 32-bit state variables (current_seed and state_high) that together give it an effective period of approximately 2⁶², far longer than a classic single-register LCG.
Call eo_srand before using the generator:
Internally, the seed is scrambled with the multiplier 22695477 before initialising current_seed, and state_high is reset to zero.
The original EO client seeded the RNG at startup using (uint32_t)time(NULL). To replicate this:
If you pass the same seed on two different runs you will get an identical sequence of random numbers, which is useful for deterministic replay or testing.
Each call to eo_rand performs the following steps:
The output is always a positive 31-bit integer in [0, 2147483647].
| Function | Description |
|---|---|
| eo_srand | Seed the generator |
| eo_rand | Generate the next pseudo-random 31-bit value |
| eo_rand_range | Generate a value in the inclusive range [min, max] |