From 9f2ef422fc63cca27c1a741eacd9bd9259ade7d8 Mon Sep 17 00:00:00 2001 From: Stig Bakken Date: Thu, 20 Sep 2001 00:50:08 +0000 Subject: [PATCH] * make better seeds in mt_srand/srand examples git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@57865 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/math.xml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/functions/math.xml b/functions/math.xml index fe301e4377..1975acc367 100644 --- a/functions/math.xml +++ b/functions/math.xml @@ -1,5 +1,5 @@ - + Mathematical Functions Math @@ -794,8 +794,12 @@ var_dump(hexdec("a0")); seed. -// seed with microseconds since last "whole" second -mt_srand ((float) microtime() * 1000000); +// seed with microseconds +function make_seed() { + list($usec,$sec) = explode(" ", microtime()); + return ((double)$sec+(double)$usec) * 100000; +} +mt_srand(make_seed()); $randval = mt_rand(); @@ -1223,8 +1227,12 @@ $foo = round(1241757, -3); // $foo == 1242000 seed. -// seed with microseconds since last "whole" second -srand ((float) microtime() * 1000000); +// seed with microseconds +function make_seed() { + list($usec,$sec) = explode(" ", microtime()); + return ((double)$sec+(double)$usec) * 100000; +} +srand(make_seed()); $randval = rand();