Class StableHash
- Namespace
- FishMMO.Shared.NameGeneration
- Assembly
- FishMMO.Shared.dll
Cross-process-stable hashing used for deterministic seed derivation.
string.GetHashCode() is randomized per AppDomain in modern .NET
(a HashDoS mitigation). That is fatal for an MMO content pipeline where
two servers MUST generate the same content from the same seed.
These helpers produce the same value across processes, runtimes, and
platforms for the same input bytes.
Algorithm: FNV-1a over UTF-8 bytes.
public static class StableHash
- Inheritance
-
StableHash
- Inherited Members
Methods
Combine(ulong, int)
public static ulong Combine(ulong acc, int value)
Parameters
Returns
Combine(ulong, long)
public static ulong Combine(ulong acc, long value)
Parameters
Returns
Combine(ulong, string)
Mix an accumulator with a follow-up string deterministically.
public static ulong Combine(ulong acc, string value)
Parameters
Returns
DeriveRng(params string[])
Produce a DeterministicRNG from the given parts. The 64-bit hash is folded to 32 bits with xor so every input bit reaches the seed; a fold to zero is remapped to one so accidental collisions on zero do not all share one stream.
public static DeterministicRNG DeriveRng(params string[] parts)
Parameters
partsstring[]
Returns
DeriveRng(ulong, int)
Produce a DeterministicRNG from a parent seed plus an index, for batch variation.
public static DeterministicRNG DeriveRng(ulong parentSeed, int index)
Parameters
Returns
FNV32(string)
public static uint FNV32(string value)
Parameters
valuestring
Returns
FNV64(string)
public static ulong FNV64(string value)
Parameters
valuestring
Returns
FoldSeed(ulong)
Folds a 64-bit hash to the 32-bit seed DeterministicRNG takes.
public static int FoldSeed(ulong hash)
Parameters
hashulong
Returns
Seed(params string[])
Build a deterministic 64-bit seed by hashing each string in order.
public static ulong Seed(params string[] parts)
Parameters
partsstring[]