Table of Contents

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

acc ulong
value int

Returns

ulong

Combine(ulong, long)

public static ulong Combine(ulong acc, long value)

Parameters

acc ulong
value long

Returns

ulong

Combine(ulong, string)

Mix an accumulator with a follow-up string deterministically.

public static ulong Combine(ulong acc, string value)

Parameters

acc ulong
value string

Returns

ulong

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

parts string[]

Returns

DeterministicRNG

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

parentSeed ulong
index int

Returns

DeterministicRNG

FNV32(string)

public static uint FNV32(string value)

Parameters

value string

Returns

uint

FNV64(string)

public static ulong FNV64(string value)

Parameters

value string

Returns

ulong

FoldSeed(ulong)

Folds a 64-bit hash to the 32-bit seed DeterministicRNG takes.

public static int FoldSeed(ulong hash)

Parameters

hash ulong

Returns

int

Seed(params string[])

Build a deterministic 64-bit seed by hashing each string in order.

public static ulong Seed(params string[] parts)

Parameters

parts string[]

Returns

ulong