|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patch mt_getrandmax-add-example for Documentation problem Bug #53207Patch version 2010-11-05 19:51 UTC Return to Bug #53207 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions:Developer: frozenfire@thefrozenfire.com
Index: en/reference/math/functions/mt-getrandmax.xml
===================================================================
--- en/reference/math/functions/mt-getrandmax.xml (revision 305106)
+++ en/reference/math/functions/mt-getrandmax.xml (working copy)
@@ -22,6 +22,32 @@
Returns the maximum random value returned by <function>mt_rand</function>
</para>
</refsect1>
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <para>
+ <example><title>Calculate a random floating-point number</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+function randomFloat($min = 0, $max = 1) {
+ return $min + mt_rand() / mt_getrandmax() * ($max - $min);
+}
+
+var_dump(randomFloat());
+var_dump(randomFloat(2, 20));
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+float(0.91601131712832)
+float(16.511210331931)
+]]>
+ </screen>
+ </example>
+ </para>
+ </refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
|
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 15:00:01 2025 UTC |