|
| 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 | +--> |
0 commit comments