Modernize the PRNG used for rand() by using a Configure option#24105
Open
scottchiefbaker wants to merge 2 commits intoPerl:bleadfrom
Open
Modernize the PRNG used for rand() by using a Configure option#24105scottchiefbaker wants to merge 2 commits intoPerl:bleadfrom
rand() by using a Configure option#24105scottchiefbaker wants to merge 2 commits intoPerl:bleadfrom
Conversation
tonycoz
reviewed
Jan 21, 2026
|
|
||
| typedef struct { uint64_t state; uint64_t inc; } pcg64_random_t; | ||
| // Global PRNG object | ||
| pcg64_random_t prng; |
Contributor
There was a problem hiding this comment.
Yeah, this should probably live in the interpreter instead. And do something sensible on thread cloning so different threads don't get the same results.
9c6eb8c to
8b56090
Compare
8b56090 to
bb9d9b5
Compare
40d4a6d to
1b78937
Compare
4029944 to
9002fb7
Compare
9002fb7 to
b0c2c62
Compare
rand() by add a Configure optionrand() by adding a Configure option
rand() by adding a Configure optionrand() by using a Configure option
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
srand()functionality works as expectedrand()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?make regenputs the functions prototypes in a weird location "Used in locale.c and perl.c"rand64()?Alternate options
rand()is "good enough"Random::Simpleis a drop-in replacement forrand()andsrand()already