* 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
This commit is contained in:
Stig Bakken 2001-09-20 00:50:08 +00:00
parent 989ca2a737
commit 9f2ef422fc

View file

@ -1,5 +1,5 @@
<?xml encoding="iso-8859-1"?>
<!-- $Revision: 1.51 $ -->
<!-- $Revision: 1.52 $ -->
<reference id="ref.math">
<title>Mathematical Functions</title>
<titleabbrev>Math</titleabbrev>
@ -794,8 +794,12 @@ var_dump(hexdec("a0"));
<parameter>seed</parameter>.
<informalexample>
<programlisting role="php">
// 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();
</programlisting>
</informalexample>
@ -1223,8 +1227,12 @@ $foo = round(1241757, -3); // $foo == 1242000
<parameter>seed</parameter>.
<informalexample>
<programlisting role="php">
// 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();
</programlisting>
</informalexample>