mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-20 19:08:54 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@273641 c90b9560-bf6c-de11-be94-00142212c4b1
127 lines
3.5 KiB
XML
127 lines
3.5 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.18 $ -->
|
|
<refentry xml:id="function.mt-rand" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>mt_rand</refname>
|
|
<refpurpose>Generate a better random value</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>mt_rand</methodname>
|
|
<void/>
|
|
</methodsynopsis>
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>mt_rand</methodname>
|
|
<methodparam><type>int</type><parameter>min</parameter></methodparam>
|
|
<methodparam><type>int</type><parameter>max</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
Many random number generators of older libcs have dubious or
|
|
unknown characteristics and are slow. By default, PHP uses the
|
|
libc random number generator with the <function>rand</function>
|
|
function. The <function>mt_rand</function> function is a drop-in
|
|
replacement for this. It uses a random number generator with
|
|
known characteristics using the <link xlink:href="&url.mersenne;">
|
|
Mersenne Twister</link>, which will produce random numbers four times
|
|
faster than what the average libc rand() provides.
|
|
</simpara>
|
|
<simpara>
|
|
If called without the optional <parameter>min</parameter>,
|
|
<parameter>max</parameter> arguments <function>mt_rand</function>
|
|
returns a pseudo-random value between 0 and
|
|
<function>mt_getrandmax</function>. If you want a random number
|
|
between 5 and 15 (inclusive), for example, use <literal>mt_rand(5,
|
|
15)</literal>.
|
|
</simpara>
|
|
¬e.randomseed;
|
|
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>min</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Optional lowest value to be returned (default: 0)
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>max</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Optional highest value to be returned (default: <function>mt_getrandmax</function>)
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
A random integer value between <parameter>min</parameter> (or 0)
|
|
and <parameter>max</parameter> (or <function>mt_getrandmax</function>, inclusive)
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>mt_rand</function> example</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
echo mt_rand() . "\n";
|
|
echo mt_rand() . "\n";
|
|
|
|
echo mt_rand(5, 15);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
1604716014
|
|
1478613278
|
|
6
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>mt_srand</function></member>
|
|
<member><function>mt_getrandmax</function></member>
|
|
<member><function>rand</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|