reference/math/functions/mt-rand.xml
2166824858a40ea664c558f2930b63b8f4fd89c6
...
...
@@ -1,153 +0,0 @@
1
-
<?xml version="1.0" encoding="utf-8"?>
2
-
<!-- $Revision$ -->
3
-
<refentry xml:id="function.mt-rand" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
4
-
<refnamediv>
5
-
<refname>mt_rand</refname>
6
-
<refpurpose>Generate a better random value</refpurpose>
7
-
</refnamediv>
8
-
<refsect1 role="description">
9
-
&reftitle.description;
10
-
<methodsynopsis>
11
-
<type>int</type><methodname>mt_rand</methodname>
12
-
<void/>
13
-
</methodsynopsis>
14
-
<methodsynopsis>
15
-
<type>int</type><methodname>mt_rand</methodname>
16
-
<methodparam><type>int</type><parameter>min</parameter></methodparam>
17
-
<methodparam><type>int</type><parameter>max</parameter></methodparam>
18
-
</methodsynopsis>
19
-
<simpara>
20
-
Many random number generators of older libcs have dubious or
21
-
unknown characteristics and are slow. By default, PHP uses the
22
-
libc random number generator with the <function>rand</function>
23
-
function. The <function>mt_rand</function> function is a drop-in
24
-
replacement for this. It uses a random number generator with
25
-
known characteristics using the <link xlink:href="&url.mersenne;">
26
-
Mersenne Twister</link>, which will produce random numbers four times
27
-
faster than what the average libc rand() provides.
28
-
</simpara>
29
-
<simpara>
30
-
If called without the optional <parameter>min</parameter>,
31
-
<parameter>max</parameter> arguments <function>mt_rand</function>
32
-
returns a pseudo-random value between 0 and
33
-
<function>mt_getrandmax</function>. If you want a random number
34
-
between 5 and 15 (inclusive), for example, use <literal>mt_rand(5,
35
-
15)</literal>.
36
-
</simpara>
37
-
</refsect1>
38
-
<refsect1 role="parameters">
39
-
&reftitle.parameters;
40
-
<para>
41
-
<variablelist>
42
-
<varlistentry>
43
-
<term><parameter>min</parameter></term>
44
-
<listitem>
45
-
<para>
46
-
Optional lowest value to be returned (default: 0)
47
-
</para>
48
-
</listitem>
49
-
</varlistentry>
50
-
<varlistentry>
51
-
<term><parameter>max</parameter></term>
52
-
<listitem>
53
-
<para>
54
-
Optional highest value to be returned (default: <function>mt_getrandmax</function>)
55
-
</para>
56
-
</listitem>
57
-
</varlistentry>
58
-
</variablelist>
59
-
</para>
60
-
</refsect1>
61
-
<refsect1 role="returnvalues">
62
-
&reftitle.returnvalues;
63
-
<para>
64
-
A random integer value between <parameter>min</parameter> (or 0)
65
-
and <parameter>max</parameter> (or <function>mt_getrandmax</function>, inclusive)
66
-
</para>
67
-
</refsect1>
68
-
<refsect1 role="changelog">
69
-
&reftitle.changelog;
70
-
<para>
71
-
<informaltable>
72
-
<tgroup cols="2">
73
-
<thead>
74
-
<row>
75
-
<entry>&Version;</entry>
76
-
<entry>&Description;</entry>
77
-
</row>
78
-
</thead>
79
-
<tbody>
80
-
&changelog.randomseed;
81
-
</tbody>
82
-
</tgroup>
83
-
</informaltable>
84
-
</para>
85
-
</refsect1>
86
-
<refsect1 role="examples">
87
-
&reftitle.examples;
88
-
<para>
89
-
<example>
90
-
<title><function>mt_rand</function> example</title>
91
-
<programlisting role="php">
92
-
<![CDATA[
93
-
<?php
94
-
echo mt_rand() . "\n";
95
-
echo mt_rand() . "\n";
96
-

97
-
echo mt_rand(5, 15);
98
-
?>
99
-
]]>
100
-
</programlisting>
101
-
&example.outputs.similar;
102
-
<screen>
103
-
<![CDATA[
104
-
1604716014
105
-
1478613278
106
-
6
107
-
]]>
108
-
</screen>
109
-
</example>
110
-
</para>
111
-
</refsect1>
112
-
<refsect1 role="notes">
113
-
&reftitle.notes;
114
-
<caution>
115
-
<para>
116
-
The distribution of <function>mt_rand</function> return values is biased
117
-
towards even numbers on 64-bit builds of PHP when
118
-
<parameter>max</parameter> is beyond <literal>2^32</literal>.
119
-
</para>
120
-
</caution>
121
-
</refsect1>
122
-
<refsect1 role="seealso">
123
-
&reftitle.seealso;
124
-
<para>
125
-
<simplelist>
126
-
<member><function>mt_srand</function></member>
127
-
<member><function>mt_getrandmax</function></member>
128
-
<member><function>rand</function></member>
129
-
</simplelist>
130
-
</para>
131
-
</refsect1>
132
-
</refentry>
133
-

134
-
<!-- Keep this comment at the end of the file
135
-
Local variables:
136
-
mode: sgml
137
-
sgml-omittag:t
138
-
sgml-shorttag:t
139
-
sgml-minimize-attributes:nil
140
-
sgml-always-quote-attributes:t
141
-
sgml-indent-step:1
142
-
sgml-indent-data:t
143
-
indent-tabs-mode:nil
144
-
sgml-parent-document:nil
145
-
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
146
-
sgml-exposed-tags:nil
147
-
sgml-local-catalogs:nil
148
-
sgml-local-ecat-files:nil
149
-
End:
150
-
vim600: syn=xml fen fdm=syntax fdl=2 si
151
-
vim: et tw=78 syn=sgml
152
-
vi: ts=1 sw=1
153
-
-->
154
0