← Back to Pull requests

Modernize the PRNG used for `rand()` by using a `Configure` option #24105

Open
unknown opened this pull request with 188 lines diff across 2 files
View on GitHub
unknown unknown commented on Jan 20, 2026 23:51 UTC
Author

Per past discussion on p5p we know the drand48 we use as a PRNG has limitations. This PR attempts to cleanly upgrade the PRNG used for rand() calls, while _leaving_ the existing drand48 code in place for internal Perl stuff (hash seed, etc). I found randfunc and seedfunc options in Configure that allow us to point at a new PRNG without affecting the existing code.

I created a new prng.h file which is largely self-contained except for a couple of additions to embed.fnc and Configure. 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 expected
Verify 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.h does 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 regen puts 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"
  • Point users at CPAN. Random::Simple is a drop-in replacement for rand() and srand() already
  • Diff: 188 lines (+141 / -47) across 2 files Reviewer: scottchiefbaker Review duration: 452373m
    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
    0.66
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 40.9% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 66.0% (HIGH) · Higher = larger blast radius
    66.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.9% · Lower = rushed or shallow review
    40.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 39.0% · Moderate risk
    39.0%
    Repository