Skip to content

Commit

Permalink
Update random
Browse files Browse the repository at this point in the history
  • Loading branch information
mowangjuanzi committed Oct 11, 2023
1 parent 2d5ef2c commit c4bced4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
21 changes: 18 additions & 3 deletions reference/random/functions/lcg-value.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 2166824858a40ea664c558f2930b63b8f4fd89c6 Maintainer: dallas Status: ready -->
<!-- EN-Revision: 67f40681074b41ddac0e11b6675df3d628a0da62 Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.lcg-value" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand All @@ -19,6 +19,20 @@
2^31 - 85 和 2^31 - 249 的两个同余发生器。本函数的周期等于这两个素数的乘积。
</para>
&caution.cryptographically-insecure;
<caution>
<para>
Scaling the return value to a different interval using multiplication
or addition (a so-called affine transformation) might result in a bias
in the resulting value as floats are not equally dense across the number
line. As not all values can be exactly represented by a float, the
result of the affine transformation might also result in values outside
of the requested interval.
</para>
<para>
使用 <methodname>Random\Randomizer::getFloat</methodname> 在任意间隔内生成随机浮点数。使用
<methodname>Random\Randomizer::getInt</methodname> 在任意间隔内生成随机整数。
</para>
</caution>
</refsect1>

<refsect1 role="parameters">
Expand All @@ -36,8 +50,9 @@
&reftitle.seealso;
<para>
<simplelist>
<member><function>rand</function></member>
<member><function>mt_rand</function></member>
<member><methodname>Random\Randomizer::getFloat</methodname></member>
<member><methodname>Random\Randomizer::getInt</methodname></member>
<member><function>random_int</function></member>
</simplelist>
</para>
</refsect1>
Expand Down
28 changes: 1 addition & 27 deletions reference/random/functions/mt-getrandmax.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 2166824858a40ea664c558f2930b63b8f4fd89c6 Maintainer: dallas Status: ready -->
<!-- EN-Revision: c174b16add554508aafdd40c5d3f2997099882b6 Maintainer: dallas Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.mt-getrandmax" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -30,32 +30,6 @@
<parameter>max</parameter> 参数而不是放大结果的最大值(更少的随机)。
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example><title>计算一个随机浮点数</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.similar;
<screen>
<![CDATA[
float(0.91601131712832)
float(16.511210331931)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
Expand Down
3 changes: 1 addition & 2 deletions reference/random/functions/mt-rand.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 826073522514072830b63bee2b6135dc675ea45d Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: 0b6c76516a299395a3703e6df44f8ea4cb4549a8 Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<refentry xml:id="function.mt-rand" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
Expand Down Expand Up @@ -149,7 +149,6 @@ echo mt_rand(5, 15), "\n";
<member><function>mt_getrandmax</function></member>
<member><function>random_int</function></member>
<member><function>random_bytes</function></member>
<member><function>rand</function></member>
</simplelist>
</para>
</refsect1>
Expand Down
3 changes: 2 additions & 1 deletion reference/random/functions/mt-srand.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 81af2a8f5da3a6ba8611eb3dc03fd5fd4e387be4 Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: c4f24e2eef1a3c970c491c0ee8cbc1f290ff023a Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.mt-srand" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -51,6 +51,7 @@
</member>
</simplelist>
</para>
&warn.deprecated.feature-8-3-0;
</listitem>
</varlistentry>
</variablelist>
Expand Down

0 comments on commit c4bced4

Please sign in to comment.