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.comIndex: 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-2024 The PHP Group All rights reserved. |
Last updated: Fri Nov 01 03:01:28 2024 UTC |