<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'random-randomizer.getbytes.php',
    1 => 'Random\\Randomizer::getBytes',
    2 => 'Get random bytes',
  ),
  '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' => 'en',
    '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">Get random bytes</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">
   Generates a string containing uniformly selected random bytes with the requested <code class="parameter">length</code>.
  </p>
  <p class="para">
   As the returned bytes are selected completely randomly, the resulting string is likely
   to contain unprintable characters or invalid UTF-8 sequences. It may be necessary to
   encode it before transmission or display.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-random-randomizer.getbytes-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">length</code></dt>
    <dd>
     <p class="para">
      The length of the random <span class="type"><a href="language.types.string.php" class="type string">string</a></span> that should be returned in bytes; must be <code class="literal">1</code> or greater.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-random-randomizer.getbytes-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   A <span class="type"><a href="language.types.string.php" class="type string">string</a></span> containing the requested number of random bytes.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-random-randomizer.getbytes-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     If the value of <code class="parameter">length</code> is less than <code class="literal">1</code>,
     a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> will be thrown.
    </span>
   </li>
   
 <li class="listitem">
  <span class="simpara">
   Any <span class="classname"><a href="class.throwable.php" class="classname">Throwable</a></span>s thrown by the <span class="methodname"><a href="random-engine.generate.php" class="methodname">Random\Engine::generate()</a></span> method
   of the underlying <a href="class.random-randomizer.php#random-randomizer.props.engine" class="link"><code class="literal">Random\Randomizer::$engine</code></a>.
  </span>
 </li>

  </ul>
 </div>


 <div class="refsect1 examples" id="refsect1-random-randomizer.getbytes-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>Random\Randomizer::getBytes()</strong></span> example</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>The above example will output
something similar to:</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">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.random-bytes.php" class="function" rel="rdfs-seeAlso">random_bytes()</a> - Get cryptographically secure random bytes</span></li>
   <li><span class="function"><a href="function.bin2hex.php" class="function" rel="rdfs-seeAlso">bin2hex()</a> - Convert binary data into hexadecimal representation</span></li>
   <li><span class="function"><a href="function.base64-encode.php" class="function" rel="rdfs-seeAlso">base64_encode()</a> - Encodes data with MIME base64</span></li>
   <li><span class="methodname"><a href="random-randomizer.getbytesfromstring.php" class="methodname" rel="rdfs-seeAlso">Random\Randomizer::getBytesFromString()</a> - Get random bytes from a source string</span></li>
  </ul>
 </div>


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