Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion reference/random/functions/random-bytes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<methodparam><type>int</type><parameter>length</parameter></methodparam>
</methodsynopsis>
<para>
Generates a string containing uniformly selected random bytes with the requested length.
Generates a string containing uniformly selected random bytes with the requested <parameter>length</parameter>.
</para>
<para>
As the returned bytes are selected completely randomly, the resulting string is likely
Expand Down
6 changes: 3 additions & 3 deletions reference/random/random/randomizer/getbytes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<methodparam><type>int</type><parameter>length</parameter></methodparam>
</methodsynopsis>
<para>
Generates a string containing uniformly selected random bytes with the requested length.
Generates a string containing uniformly selected random bytes with the requested <parameter>length</parameter>.
</para>
<para>
As the returned bytes are selected completely randomly, the resulting string is likely
Expand All @@ -28,7 +28,7 @@
<term><parameter>length</parameter></term>
<listitem>
<para>
The length of the random string that should be returned in bytes; must be <literal>1</literal> or greater.
The length of the random &string; that should be returned in bytes; must be <literal>1</literal> or greater.
</para>
</listitem>
</varlistentry>
Expand All @@ -38,7 +38,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
A string containing the requested number of random bytes.
A &string; containing the requested number of random bytes.
</para>
</refsect1>

Expand Down
54 changes: 40 additions & 14 deletions reference/random/random/randomizer/getbytesfromstring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
<methodparam><type>int</type><parameter>length</parameter></methodparam>
</methodsynopsis>
<para>

Generates a string containing uniformly selected random bytes from the
input <parameter>string</parameter> with the requested <parameter>length</parameter>.
</para>
<para>
The chance for a byte to be selected is proportional to its share
of the input <parameter>string</parameter>. If each byte occurs
the same amount of times, each byte is equally likely to be selected.
</para>

&warn.undocumented.func;

</refsect1>

<refsect1 role="parameters">
Expand All @@ -28,15 +31,15 @@
<term><parameter>string</parameter></term>
<listitem>
<para>
The string from which the returned bytes are selected.
The &string; from which the returned bytes are selected.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>length</parameter></term>
<listitem>
<para>
The length of the random string that should be returned in bytes; must be <literal>1</literal> or greater.
The length of the random &string; that should be returned in bytes; must be <literal>1</literal> or greater.
</para>
</listitem>
</varlistentry>
Expand All @@ -47,7 +50,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Description
A &string; containing the requested number of random bytes taken from the input <parameter>string</parameter>.
</para>
</refsect1>

Expand All @@ -72,22 +75,45 @@

<refsect1 role="examples">
&reftitle.examples;
<example xml:id="random-randomizer.getbytesfromstring.example.basic">
<example>
<title><methodname>Random\Randomizer::getBytesFromString</methodname> example</title>
<para>
Description.
</para>
<programlisting role="php">
<![CDATA[
<?php
echo "Code example";
$randomizer = new \Random\Randomizer();

printf(
"%s.example.com",
$randomizer->getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16)
);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
3zsw04eiubcf82jd.example.com
]]>
</screen>
</example>

<example>
<title>Generate a random code for multi-factor authentication</title>
<programlisting role="php">
<![CDATA[
<?php
// The Secure engine is the default, but we make it explicit, because
// multi-factor codes are security sensitive.
$randomizer = new \Random\Randomizer(new \Random\Engine\Secure());

echo implode('-', str_split($randomizer->getBytesFromString('0123456789', 20), 5));
?>
]]>
</programlisting>
&example.outputs;
&example.outputs.similar;
<screen>
<![CDATA[
Code example
11551-80418-27047-42075
]]>
</screen>
</example>
Expand Down