feat: add deterministic run state and events

This commit is contained in:
goose
2026-10-02 12:31:20 -04:00
parent 6cd7270e43
commit 96e708eccd
17 changed files with 249 additions and 5 deletions
+25
View File
@@ -0,0 +1,25 @@
class_name DeterministicRng
extends RefCounted
const MODULUS := 2147483647
const MULTIPLIER := 48271
var _state: int
static func from_seed(seed: String) -> DeterministicRng:
var seed_value := 0
for index in range(seed.length()):
seed_value = (seed_value * 31 + seed.unicode_at(index)) % MODULUS
if seed_value == 0:
seed_value = 1
return DeterministicRng.new(seed_value)
func _init(initial_state: int) -> void:
_state = initial_state
func next_int() -> int:
_state = (_state * MULTIPLIER) % MODULUS
return _state
func next_float() -> float:
return float(next_int()) / float(MODULUS)