1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-24 07:42:22 +01:00
Files
archived-doc-ru/reference/random/examples.xml
Mikhail Alferov d91518f0e2 Update 1bcc40f to En (#1096)
* Update book.xml to en

* Update examples.xml to en

* Update examples.xml

* Update construct.xml to en

* Update construct.xml to en

* Update construct.xml to en\

* Update construct.xml to en

* Update getint.xml to en

* Update nextint.xml to en

* Update book.xml to en
2025-08-05 11:21:34 +03:00

69 lines
1.9 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 1bcc40f8134305cbebf6c8378ee7e5fc8c569674 Maintainer: sergey Status: ready -->
<!-- Reviewed: no -->
<chapter xml:id="random.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<example>
<title>Пример генерации случайных значений методами модуля Random</title>
<programlisting role="php">
<![CDATA[
<?php
$r = new \Random\Randomizer();
// Генерация случайного доменного имени
printf(
"%s.example.com\n",
$r->getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16)
);
// Перемешивание массива:
$fruits = ['red' => '🍎', 'green' => '🥝', 'yellow' => '🍌', 'pink' => '🍑', 'purple' => '🍇'];
echo "Салат: ", implode(', ', $r->shuffleArray($fruits)), "\n";
// Выбор случайных ключей массива
$fruits = ['red' => '🍎', 'green' => '🥝', 'yellow' => '🍌', 'pink' => '🍑', 'purple' => '🍇'];
$keys = $r->pickArrayKeys($fruits, 2);
// Поиск значений выбранных ключей
$selection = array_map(
static fn($key) => $fruits[$key],
$keys
);
echo "Значения: ", implode(', ', $selection), "\n";
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
j87fzv1p0daiwmlo.example.com
Салат: 🥝, 🍇, 🍎, 🍌, 🍑
Значения: 🍌, 🍑
]]>
</screen>
</example>
</chapter>
<!-- 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:"~/.phpdoc/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
-->