Seed zones from a stable name hash instead of string.GetHashCode (Cut 10)

Closes the 8a follow-up. string.GetHashCode is stable on Mono but randomized
per process on .NET Core, so a headless sim that generates zones would get
different zones on every run.

- Extensions.StableHash folds a string's UTF-8 bytes through CultMath's pcg
  from the FNV-1a offset basis. No new CultMath API.
- ZoneGenerator seeds from `Name.StableHash() ^ pcg3d(Position).x`.
- Zone seeds from `Name.StableHash() ?? 1337u`. CultMath's Random maps
  seed 0 to its default, and the abs/Convert.ToUInt32 pair that threw on
  int.MinValue is gone.

Old runs are discarded, so a different galaxy per seed costs nothing.

Tests: StableHashIsNotProcessRandomized pins "Adrasteia" to 2427892944, the
value an independent Add-Type transcription of CultMath's pcg produced. It
fails with GetHashCode substituted back in.

Builds: headless, 15 tests pass, Unity batchmode compile reports no error CS.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-14 22:09:37 +02:00
commit 65a007e509
4 changed files with 18 additions and 3 deletions

View file

@ -1,10 +1,11 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using MessagePack;
using CultMath;
@ -20,6 +21,15 @@ public static class Extensions
return baseType.GetInterfaces().Any(interfaceType.Equals);
}
// A string hash that is the same in every process and runtime, for seeding: string.GetHashCode is randomized per
// process on .NET Core. Folds the UTF-8 bytes through CultMath's PCG hash from the FNV-1a offset basis.
public static uint StableHash(this string s)
{
uint h = 0x811C9DC5;
foreach (var b in Encoding.UTF8.GetBytes(s)) h = pcg(h ^ b);
return h;
}
// Every loadable type assignable to this one. An assembly whose dependencies are missing (a Unity plugin
// referencing UnityEngine outside Unity) still yields the types that do load.
private static readonly Dictionary<Type, Type[]> ChildClasses = new Dictionary<Type, Type[]>();