Vixen
caa30e12
csharp
public struct GameplayRandom

A reproducible random stream, seeded by what the numbers are for.

Read the guide page for this →

Remarks

Reproducible from an event id is the requirement, and it is not a nicety. Doc 28 § Loot: "the RNG is the kernel's deterministic stream seeded per drop event, so a drop is reproducible from its event id — which is what makes the log says you rolled a 3 answerable". A support ticket about a drop, a report about a crit, a dispute about a crafting quality: all of them are answerable only if the roll can be recomputed from something that was written down.

PCG-XSH-RR over a 64-bit LCG, and the choice is about being reimplementable. The whole algorithm is four integer operations with two published constants, so a tool in another language can reproduce a roll — which is what an audit actually needs. Random cannot do that: its algorithm is an implementation detail that has already changed once between .NET versions, and a seeded stream whose meaning depends on the runtime is not an audit trail.

⚠ Seeds are mixed, not combined with an operator. id ^ salt and id + salt both have inputs that cancel — Vixen.Ai's AgentRandom shipped with an XOR that made every agent in the world draw the same number, because the seed and the entity were the same hash. Mix is SplatMix64's finaliser, which has no such pair, and every constructor here goes through it.

Fields and properties (1)

  • public readonly ulong State

    Where the stream has got to. Enough to resume it exactly.

Methods (10)

  • public GameplayRandom(ulong seed)

    Makes a stream from a seed.

  • public static GameplayRandom For(ulong eventId, ulong salt = 0)

    A stream for one event, so the same event always rolls the same way.

  • public static GameplayRandom Resume(ulong state)

    Continues a stream from a stored state.

  • public uint NextUInt()

    The next 32 bits.

  • public float NextFloat()

    The next number in [0, 1).

  • public int NextInt(int bound)

    The next number in [0, bound).

  • public int NextInt(int minimum, int bound)

    The next number in [minimum, bound).

  • public bool Chance(float probability)

    Whether something with this probability happened.

  • public int Pick(ReadOnlySpan<float> weights)

    Picks an index in proportion to a list of weights.

  • public static ulong Mix(ulong value)

    SplitMix64's finaliser: an avalanche with no pair of inputs that cancels.

Used by (26)

  • SoakMmo.Soak
  • AttributeSetTestsVixen.Gameplay.Tests
  • AuctionTestsVixen.Gameplay.Economy.Tests
  • CombatResolverVixen.Gameplay.Combat
  • ConservationOracleTestsVixen.Gameplay.Inventory.Tests
  • CrafterVixen.Gameplay.Crafting
  • CriticalStrikeRuleVixen.Gameplay.Combat
  • DamageEventVixen.Gameplay.Combat
  • DynamicEventTestsVixen.Gameplay.Quests.Tests
  • GameplayRandomTestsVixen.Gameplay.Tests
  • GameplayTagTableTestsVixen.Gameplay.Tests
  • GroupTestsVixen.Gameplay.Social.Tests
  • GuildTestsVixen.Gameplay.Social.Tests
  • HousingTestsVixen.Gameplay.Housing.Tests
  • InteractionNodeVixen.Gameplay.Interaction
  • ItemAffixesVixen.Gameplay.Items
  • LedgerBridgeTestsVixen.Live.Gameplay.Tests
  • LedgerTestsVixen.Gameplay.Economy.Tests
  • LootEvaluatorVixen.Gameplay.Loot
  • MatchmakerTestsVixen.Live.Matchmaking.Tests
  • PvpMatchTestsVixen.Gameplay.Pvp.Tests
  • QuestJournalTestsVixen.Gameplay.Quests.Tests
  • SpawnTableVixen.Gameplay.Ai
  • SpawnerVixen.Gameplay.Ai
  • TradeTestsVixen.Gameplay.Economy.Tests
  • WeaponTemplateVixen.Gameplay.Shooting