Skip to content

[Core] Persist resolved random seed when RandomSeed is 0 - #1597

Merged
1337LutZ merged 1 commit into
masterfrom
core/random-seed-zero
Oct 13, 2026
Merged

1337LutZ merged 1 commit into
masterfrom
core/random-seed-zero

Conversation

@1337LutZ

Copy link
Copy Markdown

Port of wowsims/forever#407.

Problem

With RandomSeed 0 (unseeded), newSimWithEnv picks a seed from time.Now().UnixNano() for the initial generator but never writes it back to SimOptions.RandomSeed. Every iteration after the first is reseeded in reseedRands from sim.Options.RandomSeed + i, which is still 0, so iterations 1..N-1 always run with seeds 1..N-1. Each run with seed 0 replays the same fights except iteration 0.

The web UI always sends a non-zero seed (nextRngSeed), so this hits callers that send 0: wowsimcli, API requests and any request JSON without a seed.

Fix

  1. newSimWithEnv writes the resolved seed back to simOptions.RandomSeed, the same way statweight.go resolves RandomSeed == 0.
  2. SplitSimRequestForConcurrency resolves a 0 seed before splitting, so concurrent workers get distinct non-zero start seeds.
  3. Tests in rand_test.go for the write-back, the split offsets, and a fixed seed staying unchanged.

Tests

go test ./sim/core/... passes locally apart from TestProtoVersioning, which needs npx buf (not installed in the test checkout); no proto files change.

newSimWithEnv picked a time based seed for RandomSeed 0 but never wrote it
back, so reseedRands seeded iteration i with 0 + i. Only iteration 0 was
random; iterations 1..N-1 replayed the same fights on every run.

Write the resolved seed back to SimOptions, as statweight.go already does,
and resolve it in SplitSimRequestForConcurrency so split workers get
distinct non-zero start seeds.

Port of wowsims/forever#407.
@1337LutZ
1337LutZ merged commit ec2c6c2 into master Oct 13, 2026
11 checks passed
@1337LutZ
1337LutZ deleted the core/random-seed-zero branch October 13, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant