mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-17 04:45:33 -08:00
Pin Math.random in the Activities logic tests so a rare roll cannot fail one at random
AI Assisted
This commit is contained in:
1 parent
23ac3a9c19
commit
e87148ad10
43 files changed
+59
No files matched your search
@@ -0,0 +1,17 @@
|
||||
// Pins Math.random to a seeded generator for a test file that drives an Activities game, so the
|
||||
// game's own dice (a road with a crack where a test wanted plain road, a spawn that lands out of
|
||||
// reach) give the same layout on every run and a rare roll can never fail a test at random.
|
||||
// Import it FIRST in the file: a game module may roll at load time.
|
||||
//
|
||||
// A seed that fails a test is a real finding, not a flake: set PLAN2CODE_TEST_SEED to reproduce
|
||||
// another roll, for example to hunt a bug the fixed seed hides.
|
||||
|
||||
let state = Number(process.env.PLAN2CODE_TEST_SEED || 20261105) >>> 0;
|
||||
|
||||
// mulberry32: small, fast and good enough for game dice.
|
||||
Math.random = () => {
|
||||
state = (state + 0x6d2b79f5) | 0;
|
||||
let t = Math.imul(state ^ (state >>> 15), 1 | state);
|
||||
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
Reference in new issue
Block a user