Support per-process RNG for process::srandom() and object seeding (#7408) (#7415)

Fixes #7408.
This commit is contained in:
Yilou Wang
2026-04-13 13:58:53 -04:00
committed by GitHub
parent fd7a3f4a16
commit 6ba45d3383
10 changed files with 236 additions and 44 deletions
+8 -2
View File
@@ -5061,8 +5061,14 @@ AstFunc* V3Randomize::newSRandomFunc(VMemberMap& memberMap, AstClass* nodep) {
funcp->isVirtual(false);
basep->addMembersp(funcp);
memberMap.insert(nodep, funcp);
funcp->addStmtsp(new AstCStmt{basep->fileline(), "__Vm_rng.srandom(seed);"});
basep->needRNG(true);
// For std::process, seed the per-process RNG via m_process->srandom()
// For regular classes, seed the per-object RNG via __Vm_rng
if (basep->name() == "process") {
funcp->addStmtsp(new AstCStmt{basep->fileline(), "__PVT__m_process->srandom(seed);"});
} else {
funcp->addStmtsp(new AstCStmt{basep->fileline(), "__Vm_rng.srandom(seed);"});
basep->needRNG(true);
}
}
return funcp;
}