diff options
author | Tony Cook <tony@develop-help.com> | 2013-09-09 14:44:57 +1000 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2013-09-13 11:33:57 +1000 |
commit | 3be8f09452a42b9f1bbefef19be2dd11a2ca029b (patch) | |
tree | f7e06a8545aad7e0c2e96a680cebac9c06c4ff17 /util.h | |
parent | e3be4e3ed79b466668bc99904a680772e8f04697 (diff) | |
download | perl-3be8f09452a42b9f1bbefef19be2dd11a2ca029b.tar.gz |
[perl #115928] a consistent (public) rand() implementation
Based on Yves's random branch work.
This version makes the new random number visible to external modules,
for example, List::Util's XS shuffle() implementation.
I've also added a 64-bit implementation when HAS_QUAD is true, this
should be significantly faster, even on 32-bit CPUs. This is intended to
produce exactly the same sequence as the original implementation.
The original version of this commit retained the "freebsd" name from
Yves's original work for the function and data structure names. I've
removed "freebsd" from most function names so the name isn't an issue
if we choose to replace the implementation,
Diffstat (limited to 'util.h')
-rw-r--r-- | util.h | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -52,6 +52,33 @@ This is a synonym for (! foldEQ_locale()) #define ibcmp(s1, s2, len) cBOOL(! foldEQ(s1, s2, len)) #define ibcmp_locale(s1, s2, len) cBOOL(! foldEQ_locale(s1, s2, len)) +/* perl.h undefs HAS_QUAD if IV isn't 64-bit */ +#ifdef U64TYPE +/* use a faster implementation when quads are available */ +#define PERL_DRAND48_QUAD +#endif + +#ifdef PERL_DRAND48_QUAD + +/* U64 is only defined under PERL_CORE, but this needs to be visible + * elsewhere so the definition of PerlInterpreter is complete. + */ +typedef U64TYPE perl_drand48_t; + +#else + +struct PERL_DRAND48_T { + U16 seed[3]; +}; + +typedef struct PERL_DRAND48_T perl_drand48_t; + +#endif + +#define PL_RANDOM_STATE_TYPE perl_drand48_t + +#define Perl_drand48_init(seed) (Perl_drand48_init_r(&PL_random_state, (seed))) +#define Perl_drand48() (Perl_drand48_r(&PL_random_state)) /* * Local variables: |