X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=util.c;h=9a43d67fa082dc226fe24c728bcc568b2f59671c;hb=452932c35a5cd0aae80a37f9e3a551b9fc75f50d;hp=80af15519f1fce66e8db848ccb174d71197e44d0;hpb=f333445c29f1556015c4df0c417df8e1a742d36d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/util.c b/util.c index 80af155..9a43d67 100644 --- a/util.c +++ b/util.c @@ -4377,3 +4377,35 @@ Perl_seed(pTHX) return u; } +UV +Perl_get_hash_seed(pTHX) +{ + char *s = PerlEnv_getenv("PERL_HASH_SEED"); + UV myseed = 0; + + if (s) + while (isSPACE(*s)) s++; + if (s && isDIGIT(*s)) + myseed = (UV)Atoul(s); + else +#ifdef USE_HASH_SEED_EXPLICIT + if (s) +#endif + { + /* Compute a random seed */ + (void)seedDrand01((Rand_seed_t)seed()); + PL_srand_called = TRUE; + myseed = (UV)(Drand01() * (NV)UV_MAX); +#if RANDBITS < (UVSIZE * 8) + /* Since there are not enough randbits to to reach all + * the bits of a UV, the low bits might need extra + * help. Sum in another random number that will + * fill in the low bits. */ + myseed += + (UV)(Drand01() * (NV)((1 << ((UVSIZE * 8 - RANDBITS))) - 1)); +#endif /* RANDBITS < (UVSIZE * 8) */ + } + PL_hash_seed_set = TRUE; + + return myseed; +}