summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@khw-desktop.(none)>2010-07-27 08:18:25 -0600
committerRafael Garcia-Suarez <rgs@consttype.org>2010-07-28 10:07:23 +0200
commit83832992940e343002e924b1307988d2604ee165 (patch)
tree6ead241b56a400abd516361b20cf2236859d75c4 /pp.c
parent401a9b146916c60dc9bbd897355c3c83888d61f3 (diff)
downloadperl-83832992940e343002e924b1307988d2604ee165.tar.gz
srand: change to return its seed
This commit changes srand to to return the seed instead of always returning 1. The motivation behind this is to allow applications to not have to come up with their own pseudo-random generator if they want repeatable results. The previous return behavior has never been documented. Note that it is possible, but very unlikely, for the seed to end up being 0, which means that if someone were relying on the undocumented previous behavior of srand returning true, that in very rare instances it would return 0, failing, and the next time they ran it, it would succeed, possibly leading to puzzlement and very rare unexplained failures.
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/pp.c b/pp.c
index 129c94811f..ec585ab933 100644
--- a/pp.c
+++ b/pp.c
@@ -2950,12 +2950,12 @@ PP(pp_rand)
PP(pp_srand)
{
- dVAR; dSP;
+ dVAR; dSP; dTARGET;
const UV anum = (MAXARG < 1) ? seed() : POPu;
(void)seedDrand01((Rand_seed_t)anum);
PL_srand_called = TRUE;
- EXTEND(SP, 1);
- RETPUSHYES;
+ XPUSHu(anum);
+ RETURN;
}
PP(pp_int)