|
Runtime Spawner 1.5.0
Generic Runtime spawn and instance pooling system for spawning random AI agents around a map. Works with ANY AI system easily.
|
Minimal PCG32 pseudo-random number generator; fast and reproducible across platforms (including IL2CPP/AOT). More...
Public Member Functions | |
| Pcg32 (ulong seed, ulong seq=54UL) | |
| Creates a new PCG32 generator with the given seed and (optional) stream selector. | |
| uint | NextUInt () |
| Returns the next 32-bit unsigned integer and advances the generator state. | |
| int | NextInt (int minInclusive, int maxExclusive) |
Returns an integer in the half-open range [minInclusive, maxExclusive). | |
| float | NextFloat () |
Returns a float in the range [0, 1). | |
| bool | NextBool () |
| Returns a random boolean. | |
Private Attributes | |
| ulong | _state |
| Internal 64-bit LCG state. | |
| ulong | _inc |
| Per-stream increment; must be odd. Different values select independent random streams. | |
Minimal PCG32 pseudo-random number generator; fast and reproducible across platforms (including IL2CPP/AOT).
This is the 32-bit output / 64-bit state PCG variant (“pcg32”). See: https://www.pcg-random.org It’s suitable for gameplay determinism because:
ref to advance deterministically. State model: The generator keeps a 64-bit state and 64-bit increment (odd). Each call to NextUInt advances the state. Constructing with a seed performs a small warm-up so the first output depends on the seed/stream.
| MegaCrush.Spawner.Pcg32.Pcg32 | ( | ulong | seed, |
| ulong | seq = 54UL ) |
Creates a new PCG32 generator with the given seed and (optional) stream selector.
| seed | 64-bit seed value (choose any). |
| seq | Stream selector (aka “sequence” or “inc source”). This is internally forced odd as (seq << 1) | 1. Using different seq values creates statistically independent sequences for the same seed. |
The constructor performs a standard PCG initialization: set _state = 0, set _inc, step once, add seed to the state, then step again. This avoids low-entropy first outputs.
| bool MegaCrush.Spawner.Pcg32.NextBool | ( | ) |
Returns a random boolean.
| float MegaCrush.Spawner.Pcg32.NextFloat | ( | ) |
Returns a float in the range [0, 1).
Converts the top ~24 random bits to a IEEE-754 single by multiplying by 1/2^24. This mirrors the typical precision of Unity’s Random.value while remaining deterministic across platforms.
| int MegaCrush.Spawner.Pcg32.NextInt | ( | int | minInclusive, |
| int | maxExclusive ) |
Returns an integer in the half-open range [minInclusive, maxExclusive).
| minInclusive | Inclusive lower bound. |
| maxExclusive | Exclusive upper bound (must be > minInclusive ). |
Uses modulo reduction of NextUInt; this is extremely fast and the slight modulo bias is negligible for typical gameplay ranges. If you require mathematically uniform bounded integers (e.g., cryptographic or fairness-critical cases), implement rejection sampling instead.
| uint MegaCrush.Spawner.Pcg32.NextUInt | ( | ) |
Returns the next 32-bit unsigned integer and advances the generator state.
Core PCG step: LCG update followed by xorshift and rotate to decorrelate bits (this is the “XSH RR” output function in PCG literature).
|
private |
Per-stream increment; must be odd. Different values select independent random streams.
|
private |
Internal 64-bit LCG state.