mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 07:22:16 +01:00
135 lines
3.9 KiB
XML
135 lines
3.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 126eefa0db9fd7fa66ace49dc86157f7ec676d33 Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: no Maintainer: andresdzphp -->
|
|
<refentry xml:id="function.array-rand" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>array_rand</refname>
|
|
<refpurpose>Seleccionar una o más claves aleatorias de un array</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>array_rand</methodname>
|
|
<methodparam><type>array</type><parameter>array</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>num</parameter><initializer>1</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Selecciona uno o más valores aleatorios de un array y devuelve la
|
|
clave (o claves) de dichos valores aleatorios.
|
|
Utiliza un generador de números seudoaleatorios que no es apto para
|
|
fines criptográficos.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El array de entrada.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>num</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Especifica cuántas entradas deberían seleccionarse.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Al seleccionar solamente una entrada, <function>array_rand</function> devolverá
|
|
la clave para una entrada aleatoria. De lo contrario, devolverá un array con las claves
|
|
de las entradas aleatorias. Esto se realiza de tal manera que se pueden seleccionar del array
|
|
tanto claves como valores aleatorios. Intentar seleccionar más elementos
|
|
de los que hay en el array resultará en un
|
|
error de nivel <constant>E_WARNING</constant>, devolviendo NULL .
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>7.1.0</entry>
|
|
<entry>
|
|
El algoritmo de aleatorización interno <link linkend="migration71.incompatible.rand-srand-aliases">se ha cambiado</link> para usar el generador de números aleatorios <link xlink:href="&url.mersenne;">Mersenne Twister</link> en lugar de la función libc rand.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>5.2.10</entry>
|
|
<entry>
|
|
El array de claves resultante ya no se mezcla.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <function>array_rand</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$entrada = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
|
|
$claves_aleatorias = array_rand($entrada, 2);
|
|
echo $entrada[$claves_aleatorias[0]] . "\n";
|
|
echo $entrada[$claves_aleatorias[1]] . "\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>shuffle</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|