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
=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 $
}
}
+/* 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;
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
anum = seed();
else
anum = POPu;
- (void)srand((unsigned)anum);
+ (void)my_srand((unsigned)anum);
srand_called = TRUE;
EXTEND(SP, 1);
RETPUSHYES;