Modernize the PRNG used for `rand()` by using a `Configure` option #24105
All Vouch review confidence checks passed
Residual risk 0.39 = Change Risk (0.66) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.66 · 188 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.314
Sensitive Paths
sensitive_paths
0.066
Real PR Conversation Timeline
1 comments
"Review active on #24105"
general
weight: 0.35
scottchiefbaker
Per past discussion on p5p we know the
drand48we use as a PRNG has limitations. This PR attempts to cleanly upgrade the PRNG used forrand()calls, while _leaving_ the existing drand48 code in place for internal Perl stuff (hash seed, etc). I foundrandfuncandseedfuncoptions in Configure that allow us to point at a new PRNG without affecting the existing code.I created a new
prng.hfile which is largely self-contained except for a couple of additions toembed.fncandConfigure. I have included two new PRNG implementations: PCG64 (my preference) ~and xoroshiro128* as options~.Completed items
Modern PRNG implementation (PCG64)
Detailed instructions for future devs on how to extend and modify
Updated unit tests
Verify
srand()functionality works as expectedVerify the new
rand()outputs the full 53 bit state capable from a double (drand48 could only do 48 bits)./perl -I lib -E 'for (1..5) { printf("%064b\n", rand()2*64-1); }'TODO
~
prng.hdoes not seem to be rebuilt consistently after changes. Do I need to add this new file to build system?~Bikeshed on what the best PRNG is in 2026
~
make regenputs the functions prototypes in a weird location "Used in locale.c and perl.c"~Add an option to get a random integer?
rand64()?Alternate options
We don't do anything.
rand()is "good enough"Random::Simpleis a drop-in replacement forrand()andsrand()already