Slay the Spire 2 Correlated Randomness Bug

Slay the Spire 2 (beta patch v0.107.0) contains a significant bug where different pseudorandom number generators (PRNGs) are correlated. This means that the output of one RNG can be used to predict the outputs of others, fundamentally altering the intended probabilities of card drops, relic effects, and enemy behavior.

The Cause: Linear Seeds in C# System.Random

Slay the Spire 2 attempts to prevent randomness in one area of combat from affecting future rewards by using multiple distinct RNGs. Each RNG is initialized with a seed modified by a hash of its purpose (e.g., seed + hash("shuffle")).

However, the game uses the stock System.Random class in C#. The PRNG algorithm in this class is almost entirely linear in its starting seed. Consequently, two RNGs whose seeds differ by a known fixed amount produce outputs that differ by a predictable amount. Because the game's RNG seeds are offset by fixed hash values, the outputs remain correlated across different game systems.

Gameplay Impacts of Correlated Randomness

This correlation creates systemic biases that affect nearly every aspect of a run, from the first encounter to late-game events.

Neow's Relics and Curses

Certain relics offered by Neow are intrinsically biased based on the Act 1 variant (Underdocks or Overgrowth):

  • Neow's Bones: In Underdocks, the random curse received is approximately 54% likely to be Debt, whereas in Overgrowth, it is 73.74% likely to be Writhe. This makes the relic significantly worse in Underdocks due to the higher frequency of crippling curses.
  • Large Capsule: This relic never provides a common relic. In Overgrowth, it is ~70% likely to be uncommon and ~30% rare. In Underdocks, it is ~37% uncommon and ~63% rare.
  • Small Capsule: While not intrinsically biased, its output can be predicted by the presence of other curse pool relics. For example, it usually provides a common relic in Underdocks and an uncommon or rare relic in Overgrowth.

Card Transforms and Rare Rewards

Predictability extends to card transformations and rare card selection:

  • Leafy Poultice: The first transform provided by this relic is limited to only 22 possibilities out of the character's 80-card pool.
  • Hefty Tablet: In Underdocks, the first option is limited to only 3 possibilities; in Overgrowth, it is limited to 11.
  • Arcane Scroll and New Leaf: The possible transforms or rare cards can be narrowed down to as few as 3 to 12 options depending on the act and the Neow relic seen.

Combat and Event Predictability

  • Potion Drops: The chance of the first fight dropping a potion is 76% in Underdocks and only 4% in Overgrowth.
  • Trash Heap Event: In single-player mode, it is mathematically impossible to obtain the card Rebound from the Trash Heap event because the act RNG rolling Underdocks imposes a constraint that excludes Rebound from the output range.
  • Targeting: For Defect players, the first lightning orb in the first Underdocks fight is 75% likely to hit the enemy on the left.
  • Doll Room: The doll received from the "one doll" option in Act 2 can be predicted with high accuracy based on the Neow relic offered at the start of the run.

Technical Solutions and Recommendations

To eliminate this correlation, the game must move away from the linear properties of System.Random.

Recommended Fixes

  1. Nonlinear PRNG Implementation: Replacing System.Random with a modern, nonlinear PRNG such as PCG32 would immediately eliminate the correlation.
  2. Nonlinear Seeding: A simpler, though less robust, fix would be to generate seeds using nonlinear operations (like multiplication) rather than addition.
  3. Custom PRNG Codebase: Implementing the PRNG directly within the game code rather than relying on the platform's standard library ensures that seeds are identical across all platforms (Desktop vs. Mobile) and remain consistent across future library updates.

Community Insights

Technical observers noted that the game's use of C# System.Random within the Godot engine created this vulnerability, whereas Godot's own GDScript RNG class uses PCG32, which is not susceptible to this specific linear correlation issue.

"Game developers should consider gameplay-relevant random generators part of their gameplay code rather than platform code."

This discovery highlights the critical importance of using deterministic, nonlinear PRNGs for strategy games where seed-based runs and balance are paramount.

Sources