Skip to content

Commit 6389ba4

Browse files
committed
[reference/random] add random examples
1 parent e12ddda commit 6389ba4

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

reference/random/examples.xml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
<!-- EN-Revision: 1bcc40f8134305cbebf6c8378ee7e5fc8c569674 Maintainer: mumumu Status: ready -->
4+
<chapter xml:id="random.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5+
&reftitle.examples;
6+
<example>
7+
<title>Random の例</title>
8+
<programlisting role="php">
9+
<![CDATA[
10+
<?php
11+
$r = new \Random\Randomizer();
12+
13+
// ランダムなドメイン名を生成する
14+
printf(
15+
"%s.example.com\n",
16+
$r->getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16)
17+
);
18+
19+
// 配列をシャッフルする:
20+
$fruits = [ 'red' => '🍎', 'green' => '🥝', 'yellow' => '🍌', 'pink' => '🍑', 'purple' => '🍇' ];
21+
echo "Salad: ", implode(', ', $r->shuffleArray($fruits)), "\n";
22+
23+
// 配列のキーをシャッフルする
24+
$fruits = [ 'red' => '🍎', 'green' => '🥝', 'yellow' => '🍌', 'pink' => '🍑', 'purple' => '🍇' ];
25+
26+
$keys = $r->pickArrayKeys($fruits, 2);
27+
// 選択したキーの値を調べる
28+
$selection = array_map(
29+
static fn ($key) => $fruits[$key],
30+
$keys
31+
);
32+
33+
echo "Values: ", implode(', ', $selection), "\n";
34+
?>
35+
]]>
36+
</programlisting>
37+
&example.outputs.similar;
38+
<screen>
39+
<![CDATA[
40+
j87fzv1p0daiwmlo.example.com
41+
Salad: 🥝, 🍇, 🍎, 🍌, 🍑
42+
Values: 🍌, 🍑
43+
]]>
44+
</screen>
45+
</example>
46+
</chapter>
47+
<!-- Keep this comment at the end of the file
48+
Local variables:
49+
mode: sgml
50+
sgml-omittag:t
51+
sgml-shorttag:t
52+
sgml-minimize-attributes:nil
53+
sgml-always-quote-attributes:t
54+
sgml-indent-step:1
55+
sgml-indent-data:t
56+
indent-tabs-mode:nil
57+
sgml-parent-document:nil
58+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
59+
sgml-exposed-tags:nil
60+
sgml-local-catalogs:nil
61+
sgml-local-ecat-files:nil
62+
End:
63+
vim600: syn=xml fen fdm=syntax fdl=2 si
64+
vim: et tw=78 syn=sgml
65+
vi: ts=1 sw=1
66+
-->

reference/random/reference.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
<!-- EN-Revision: 2166824858a40ea664c558f2930b63b8f4fd89c6 Maintainer: mumumu Status: ready -->
4+
<reference xml:id="ref.random" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5+
<title>Random &Functions;</title>
6+
7+
&reference.random.entities.functions;
8+
9+
</reference>
10+
<!-- Keep this comment at the end of the file
11+
Local variables:
12+
mode: sgml
13+
sgml-omittag:t
14+
sgml-shorttag:t
15+
sgml-minimize-attributes:nil
16+
sgml-always-quote-attributes:t
17+
sgml-indent-step:1
18+
sgml-indent-data:t
19+
indent-tabs-mode:nil
20+
sgml-parent-document:nil
21+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
22+
sgml-exposed-tags:nil
23+
sgml-local-catalogs:nil
24+
sgml-local-ecat-files:nil
25+
End:
26+
vim600: syn=xml fen fdm=syntax fdl=2 si
27+
vim: et tw=78 syn=sgml
28+
vi: ts=1 sw=1
29+
-->

0 commit comments

Comments
 (0)