php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #53207
Patch mt_getrandmax-add-example revision 2010-11-05 19:51 UTC by frozenfire at thefrozenfire dot com
revision 2010-11-05 19:35 UTC by frozenfire at thefrozenfire dot com

Patch mt_getrandmax-add-example for Documentation problem Bug #53207

Patch version 2010-11-05 19:35 UTC

Return to Bug #53207 | Download this patch
This patch is obsolete

Obsoleted by 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,31 @@
    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[
+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>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 01 03:01:28 2024 UTC