public static class AgentRandomRandom numbers keyed on the agent, so a replay makes the same choice.
Remarks
Stateless, and keyed on identity rather than on a slot. A weighted-random selector reading Random.Shared is a desync per NPC per second: two machines running the same build would draw in whatever order their threads happened to reach the agents, and the choices would diverge within a frame. A value here is a pure function of who is asking, on which stream, for what, so any thread can compute any agent's number at any time without having computed anybody else's first.
⚠ The salt is not optional. Two uses of randomness on one agent must not agree with each other, or a RandomSelector and a service's random deviation would draw the same number and every agent that took the first branch would also tick early — a correlation that looks like behaviour and is not. The salt is what the number is for: a node's execution index, an action's index, a named constant.
The mixing function is VfxRandom's — Chris Wellons' lowbias32, three multiplies and three xor-shifts, no avalanche anomalies — and it is copied rather than shared because the two live in sibling assemblies and neither may reference the other. When a third caller wants it, the hash is what moves to Vixen.Core, not this type: a particle's stream is keyed on an identifier and a graph operation, an agent's on an entity and a node, and the two contracts are not the same one.
Methods (6)
public static uint SeedOf(Entity entity)A stream seed for an entity, stable across runs and machines.
public static uint Hash(uint value)Mixes one integer.
public static uint Hash(Entity entity, uint seed, uint salt)Mixes an agent, a stream and a use.
public static float Value(Entity entity, uint seed, uint salt)A number in [0,1).
public static float Range(Entity entity, uint seed, uint salt, float minimum, float maximum)A number in a range.
public static int Index(Entity entity, uint seed, uint salt, int count)An index into a set.
Used by (12)
- AgentContextVixen.Ai
- AgentRandomTestsVixen.Ai.Tests
- AiSystemVixen.Ai
- AiSystemTestsVixen.Ai.Tests
- BehaviorTreeCostTestsVixen.Ai.Tests
- BehaviorTreeInstanceVixen.Ai
- BehaviorTreeServiceTestsVixen.Ai.Tests
- GoapHarnessVixen.Ai.Tests
- HarnessVixen.Ai.Tests
- PerceptionSystemVixen.Ai.Perception
- TreeHarnessVixen.Ai.Tests
- UtilitySelectorTestsVixen.Ai.Tests