From: Andy Dougherty Date: Wed, 15 Jul 1998 14:23:39 +0000 (-0400) Subject: Re: Configure s?rand support [PATCH 5.004_75] -- better patch X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=56cb0a1cdc8ec02cd8a47636454b897d7f8bb403;p=p5sagit%2Fp5-mst-13.2.git Re: Configure s?rand support [PATCH 5.004_75] -- better patch Message-Id: p4raw-id: //depot/perl@1551 --- diff --git a/INSTALL b/INSTALL index aadf2c7..fe78b1b 100644 --- a/INSTALL +++ b/INSTALL @@ -773,14 +773,18 @@ config.sh. For example, you can replace the rand() and srand() functions in the perl source by any other random number generator by a trick such as the -following: +following (this should all be on one line): - sh Configure -Dccflags='-Drand=random -Dsrand=srandom' + sh Configure -Dccflags='-Dmy_rand=random -Dmy_srand=srandom' \ + -Drandbits=31 -or by adding -Drand=random and -Dsrand=srandom to your ccflags -at the appropriate Configure prompt. (Note: Although this worked for -me, it might not work for you if your system's header files give -different prototypes for rand() and random() or srand() and srandom().) +or you can use the drand48 family of functions with + + sh Configure -Dccflags='-Dmy_rand=lrand48 -Dmy_srand=srand48' \ + -Drandbits=31 + +or by adding the -D flags to your ccflags at the appropriate Configure +prompt. (Read pp.c to see how this works.) You should also run Configure interactively to verify that a hint file doesn't inadvertently override your ccflags setting. (Hints files @@ -1573,4 +1577,4 @@ the contact information to match your distribution. =head1 LAST MODIFIED -$Id: INSTALL,v 1.40 1998/07/06 14:49:02 doughera Released $ +$Id: INSTALL,v 1.42 1998/07/15 18:04:44 doughera Released $ diff --git a/pp.c b/pp.c index 8625a39..ff37a9f 100644 --- a/pp.c +++ b/pp.c @@ -1550,6 +1550,19 @@ PP(pp_cos) } } +/* Support Configure command-line overrides for rand() functions. + After 5.005, perhaps we should replace this by Configure support + for drand48(), random(), or rand(). For 5.005, though, maintain + compatibility by calling rand() but allow the user to override it. + See INSTALL for details. --Andy Dougherty 15 July 1998 +*/ +#ifndef my_rand +# define my_rand rand +#endif +#ifndef my_srand +# define my_srand srand +#endif + PP(pp_rand) { djSP; dTARGET; @@ -1561,19 +1574,19 @@ PP(pp_rand) if (value == 0.0) value = 1.0; if (!srand_called) { - (void)srand((unsigned)seed()); + (void)my_srand((unsigned)seed()); srand_called = TRUE; } #if RANDBITS == 31 - value = rand() * value / 2147483648.0; + value = my_rand() * value / 2147483648.0; #else #if RANDBITS == 16 - value = rand() * value / 65536.0; + value = my_rand() * value / 65536.0; #else #if RANDBITS == 15 - value = rand() * value / 32768.0; + value = my_rand() * value / 32768.0; #else - value = rand() * value / (double)(((unsigned long)1) << RANDBITS); + value = my_rand() * value / (double)(((unsigned long)1) << RANDBITS); #endif #endif #endif @@ -1589,7 +1602,7 @@ PP(pp_srand) anum = seed(); else anum = POPu; - (void)srand((unsigned)anum); + (void)my_srand((unsigned)anum); srand_called = TRUE; EXTEND(SP, 1); RETPUSHYES;