[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-doc-cvs
Subject:    [DOC-CVS] [doc-en] master: random: Remove examples for mt_srand() and srand() (#2304)
From:       Tim_Düsterhus_via_GitHub <noreply () php ! net>
Date:       2023-02-21 10:46:57
Message-ID: 7hU3PWvEZr6ZcRO8Ul6qITW4krWXvUbo8pnb5DY0F8A () main ! php ! net
[Download RAW message or body]

Author: Tim Düsterhus (TimWolla)
Committer: GitHub (web-flow)
Pusher: TimWolla
Date: 2023-02-21T11:33:49+01:00

Commit: https://github.com/php/doc-en/commit/823cfabfbd98d69e7bae993c5edc6e92a20bab77
Raw diff: https://github.com/php/doc-en/commit/823cfabfbd98d69e7bae993c5edc6e92a20bab77.diff

random: Remove examples for mt_srand() and srand() (#2304)

These examples teach the readers bad practices, because they indicate that
seeding from the current time is reasonable (it is not). Users should ideally
use the `random_int()` function. If that is not possible, the
`Random\Randomizer` is the next best choice. If that's not an option either,
then relying on the random seed of the global Mt19937 is better than any manual
seeding that relies on the current time.

Changed paths:
  M  reference/random/functions/mt-srand.xml
  M  reference/random/functions/srand.xml


Diff:

diff --git a/reference/random/functions/mt-srand.xml b/reference/random/functions/mt-srand.xml
index 2600af8f066..2ea780e57b3 100644
--- a/reference/random/functions/mt-srand.xml
+++ b/reference/random/functions/mt-srand.xml
@@ -93,28 +93,6 @@
    </informaltable>
   </para>
  </refsect1>
- <refsect1 role="examples">
-  &reftitle.examples;
-  <para>
-   <example>
-    <title><function>mt_srand</function> example</title>
-    <programlisting role="php">
-<![CDATA[
-<?php
-// seed with microseconds
-function make_seed()
-{
-  list($usec, $sec) = explode(' ', microtime());
-  return $sec + $usec * 1000000;
-}
-mt_srand(make_seed());
-$randval = mt_rand();
-?>
-]]>
-    </programlisting>
-   </example>
-  </para>
- </refsect1>
  <refsect1 role="seealso">
   &reftitle.seealso;
   <para>
diff --git a/reference/random/functions/srand.xml b/reference/random/functions/srand.xml
index e229e84aada..b92e7434620 100644
--- a/reference/random/functions/srand.xml
+++ b/reference/random/functions/srand.xml
@@ -67,28 +67,6 @@
    </informaltable>
   </para>
  </refsect1>
- <refsect1 role="examples">
-  &reftitle.examples;
-  <para>
-   <example>
-    <title><function>srand</function> example</title>
-    <programlisting role="php">
-<![CDATA[
-<?php
-// seed with microseconds
-function make_seed()
-{
-  list($usec, $sec) = explode(' ', microtime());
-  return $sec + $usec * 1000000;
-}
-srand(make_seed());
-$randval = rand();
-?>
-]]>
-    </programlisting>
-   </example>
-  </para>
- </refsect1>
  <refsect1 role="seealso">
   &reftitle.seealso;
   <para>

-- 
PHP Documentation Commits Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic