<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.random-randomizer.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'random-randomizer.getbytes.php',
    1 => 'Random\\Randomizer::getBytes',
    2 => 'Renvoie des octets al&eacute;atoires',
  ),
  'up' => 
  array (
    0 => 'class.random-randomizer.php',
    1 => 'Random\\Randomizer',
  ),
  'prev' => 
  array (
    0 => 'random-randomizer.construct.php',
    1 => 'Random\\Randomizer::__construct',
  ),
  'next' => 
  array (
    0 => 'random-randomizer.getbytesfromstring.php',
    1 => 'Random\\Randomizer::getBytesFromString',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/random/random/randomizer/getbytes.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="random-randomizer.getbytes" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Random\Randomizer::getBytes</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.2.0)</p><p class="refpurpose"><span class="refname">Random\Randomizer::getBytes</span> &mdash; <span class="dc-title">Renvoie des octets aléatoires</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-random-randomizer.getbytes-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Random\Randomizer::getBytes</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$length</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   Génère une chaîne contenant des octets aléatoires uniformément sélectionnés de la <code class="parameter">length</code> demandée.
  </p>
  <p class="para">
   Comme les octets retournés sont sélectionnés de manière complètement aléatoire, la chaîne résultante est susceptible
   de contenir des caractères non imprimables ou des séquences UTF-8 invalides. Il peut être nécessaire
   de l&#039;encoder avant de la transmettre ou de l&#039;afficher.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-random-randomizer.getbytes-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <dl>
   
    <dt><code class="parameter">length</code></dt>
    <dd>
     <p class="para">
      La longueur de la chaîne aléatoire <a href="language.types.string.php" class="link">chaîne de caractères</a> qui doit être retournée en octets; doit être <code class="literal">1</code> ou plus.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-random-randomizer.getbytes-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Une <a href="language.types.string.php" class="link">chaîne de caractères</a> contenant le nombre demandé d&#039;octets aléatoires.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-random-randomizer.getbytes-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     Si la valeur de <code class="parameter">length</code> est inférieure à <code class="literal">1</code>,
     une <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> sera lancée.
    </span>
   </li>
   
 <li class="listitem">
  <span class="simpara">
   Tout <span class="classname"><a href="class.throwable.php" class="classname">Throwable</a></span>s lancé par la méthode <span class="methodname"><a href="random-engine.generate.php" class="methodname">Random\Engine::generate()</a></span>
   du <a href="class.random-randomizer.php#random-randomizer.props.engine" class="link"><code class="literal">Random\Randomizer::$engine</code></a> sous-jacent.
  </span>
 </li>

  </ul>
 </div>


 <div class="refsect1 examples" id="refsect1-random-randomizer.getbytes-examples">
  <h3 class="title">Exemples</h3>
  <div class="example" id="example-1">
   <p><strong>Exemple #1 Exemple de <span class="function"><strong>Random\Randomizer::getBytes()</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 />$r </span><span style="color: #007700">= new </span><span style="color: #0000BB">\Random\Randomizer</span><span style="color: #007700">();<br /><br />echo </span><span style="color: #0000BB">bin2hex</span><span style="color: #007700">(</span><span style="color: #0000BB">$r</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getBytes</span><span style="color: #007700">(</span><span style="color: #0000BB">8</span><span style="color: #007700">)), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Résultat de l&#039;exemple ci-dessus est similaire à :</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">ebdbe93cd56682c2</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-random-randomizer.getbytes-seealso">
  <h3 class="title">Voir aussi</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.random-bytes.php" class="function" rel="rdfs-seeAlso">random_bytes()</a> - R&eacute;cup&egrave;re des octets al&eacute;atoires cryptographiquement s&eacute;curis&eacute;s</span></li>
   <li><span class="function"><a href="function.bin2hex.php" class="function" rel="rdfs-seeAlso">bin2hex()</a> - Convertit des donn&eacute;es binaires en repr&eacute;sentation hexad&eacute;cimale</span></li>
   <li><span class="function"><a href="function.base64-encode.php" class="function" rel="rdfs-seeAlso">base64_encode()</a> - Encode une cha&icirc;ne en MIME base64</span></li>
   <li><span class="methodname"><a href="random-randomizer.getbytesfromstring.php" class="methodname" rel="rdfs-seeAlso">Random\Randomizer::getBytesFromString()</a> - Renvoie des octets al&eacute;atoires &agrave; partir d'une cha&icirc;ne</span></li>
  </ul>
 </div>


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