summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--INSTALL18
-rw-r--r--pp.c25
2 files changed, 30 insertions, 13 deletions
diff --git a/INSTALL b/INSTALL
index aadf2c7c24..fe78b1b6b9 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 8625a3957e..ff37a9f8f1 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;