<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.str-shuffle.php',
    1 => 'str_shuffle',
    2 => '文字列をランダムにシャッフルする',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String 関数',
  ),
  'prev' => 
  array (
    0 => 'function.str-rot13.php',
    1 => 'str_rot13',
  ),
  'next' => 
  array (
    0 => 'function.str-split.php',
    1 => 'str_split',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/strings/functions/str-shuffle.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.str-shuffle" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">str_shuffle</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">str_shuffle</span> &mdash; <span class="dc-title">文字列をランダムにシャッフルする</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.str-shuffle-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>str_shuffle</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
   <span class="function"><strong>str_shuffle()</strong></span> は文字列をシャッフルします。
   考えられるすべての順列のうちのひとつを作成します。
  </p>
  <div class="caution"><strong class="caution">警告</strong>
 <p class="para">
  この関数が生成する値は、暗号学的にセキュアではありません。そのため、これを暗号や、戻り値を推測できないことが必須の値として使っては <em>いけません</em>。
 </p>
 <p class="para">
  暗号学的にセキュアな乱数が必要な場合は、<span class="classname"><a href="class.random-randomizer.php" class="classname">Random\Randomizer</a></span> を <span class="classname"><a href="class.random-engine-secure.php" class="classname">Random\Engine\Secure</a></span> と一緒に使いましょう。簡単なユースケースの場合、<span class="function"><a href="function.random-int.php" class="function">random_int()</a></span> と <span class="function"><a href="function.random-bytes.php" class="function">random_bytes()</a></span> 関数が、オペレーティングシステムの <abbr title="Cryptographically Secure PseudoRandom Number Generator">CSPRNG</abbr> を使った、 便利で安全な <abbr title="Application Programming Interface">API</abbr> を提供します。
 </p>
</div>
  <div class="caution"><strong class="caution">警告</strong>
 <p class="simpara">
    この関数は、乱数のソースとしてグローバルな Mt19937 (メルセンヌ・ツイスター) インスタンスを使用するため、グローバルな Mt19937 を使用する他のすべての関数と状態を共有します。
    これらの関数のいずれかを使用すると、スコープに関係なく、<em>すべての</em>他の関数のシーケンスも進みます。
  </p>
  <p class="simpara">
    <span class="function"><a href="function.mt-srand.php" class="function">mt_srand()</a></span> または <span class="function"><a href="function.srand.php" class="function">srand()</a></span> に既知の値を指定してシードすることで再現可能なシーケンスを生成する場合、この関数からの出力も再現可能になります。
  </p>
  <p class="simpara">
    新しく書くコードでは、すべて <span class="classname"><a href="class.random-randomizer.php" class="classname">Random\Randomizer</a></span> のメソッドを使用することを推奨します。
 </p>
</div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.str-shuffle-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       入力文字列。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.str-shuffle-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   シャッフルされた文字列を返します。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.str-shuffle-changelog">
  <h3 class="title">変更履歴</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>バージョン</th>
       <th>説明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.1.0</td>
       <td>
        内部的なランダム化アルゴリズムは、
        libc の rand 関数ではなく、
        <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html" class="link external">&raquo;&nbsp;メルセンヌツイスタ</a>
        乱数生成器を使うように
        <a href="migration71.incompatible.php#migration71.incompatible.rand-srand-aliases" class="link">変更されました</a>
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.str-shuffle-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="function"><strong>str_shuffle()</strong></span> の例</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">'abcdef'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$shuffled </span><span style="color: #007700">= </span><span style="color: #0000BB">str_shuffle</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// bfdaec のような文字列を返します<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$shuffled</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.str-shuffle-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="random-randomizer.shufflebytes.php" class="function" rel="rdfs-seeAlso">Random\Randomizer::shuffleBytes()</a> - 指定された文字列の、バイト単位の順列を取得する</span></li>
    <li><span class="function"><a href="random-randomizer.shufflearray.php" class="function" rel="rdfs-seeAlso">Random\Randomizer::shuffleArray()</a> - 配列の順列を取得する</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>