mirror of
https://github.com/php/doc-es.git
synced 2026-04-23 23:28:22 +02:00
186 lines
5.4 KiB
XML
186 lines
5.4 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: d6dc2be3c5c70e4a1c3d13f788643ea232747c19 Maintainer: PhilDaiguille Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
|
|
<refentry xml:id="function.rand" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>rand</refname>
|
|
<refpurpose>Genera un valor aleatorio</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>rand</methodname>
|
|
<void/>
|
|
</methodsynopsis>
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>rand</methodname>
|
|
<methodparam><type>int</type><parameter>min</parameter></methodparam>
|
|
<methodparam><type>int</type><parameter>max</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
Llamada sin los argumentos <parameter>min</parameter> y
|
|
<parameter>max</parameter>, <function>rand</function> devuelve un
|
|
número pseudoaleatorio entre 0 y <function>getrandmax</function>.
|
|
Si se desea un número aleatorio entre 5 y 15
|
|
(inclusive), por ejemplo, se puede utilizar <literal>rand (5, 15)</literal>.
|
|
</simpara>
|
|
&caution.cryptographically-insecure;
|
|
&caution.mt19937-global-state;
|
|
<note>
|
|
<simpara>
|
|
Antes de PHP 7.1.0, <function>getrandmax</function> valía solo 32767 en ciertas plataformas
|
|
(como Windows). Si se necesita un rango superior a 32767, se recomienda especificar
|
|
un valor límite superior a 32767, al especificar <parameter>min</parameter> y
|
|
<parameter>max</parameter>, se permitirá utilizar un intervalo
|
|
más grande que <function>mt_getrandmax</function>, o bien, utilizar la función
|
|
<function>mt_rand</function> en su lugar.
|
|
</simpara>
|
|
</note>
|
|
<note><simpara>A partir de PHP 7.1.0, <function>rand</function> utiliza el mismo
|
|
generador de números aleatorios que <function>mt_rand</function>. Para
|
|
preservar la compatibilidad ascendente, <function>rand</function> permite que
|
|
<parameter>max</parameter> sea más pequeño que <parameter>min</parameter>
|
|
en oposición al retorno &false; de <function>mt_rand</function></simpara>
|
|
</note>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>min</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El valor más pequeño a devolver (por omisión, 0)
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>max</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El valor más grande a devolver (por omisión, <function>mt_getrandmax</function>)
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Un valor pseudoaleatorio, comprendido entre
|
|
<parameter>min</parameter> (o 0) y
|
|
<parameter>max</parameter> (o <function>mt_getrandmax</function>, inclusive).
|
|
</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.2.0</entry>
|
|
<entry>
|
|
<function>rand</function>
|
|
<link linkend="migration72.incompatible.rand-mt_rand-output">recibió una corrección de error</link>
|
|
para un bug de polarización módulo. Esto significa que las secuencias
|
|
generadas en ciertos casos específicos pueden diferir de PHP 7.1 en
|
|
las máquinas de 64 bits.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>7.1.0</entry>
|
|
<entry>
|
|
<function>rand</function> <link linkend="migration71.incompatible.rand-srand-aliases">fue hecho</link> un alias de <function>mt_rand</function>.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo con <function>rand</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
echo rand(), "\n";
|
|
echo rand(), "\n";
|
|
|
|
echo rand(5, 15), "\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
7771
|
|
22264
|
|
11
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<warning>
|
|
<para>
|
|
El rango <parameter>min</parameter> <parameter>max</parameter> debe situarse
|
|
dentro del rango <function>getrandmax</function>. es decir,
|
|
abs(<parameter>max</parameter> - <parameter>min</parameter>) <=
|
|
<function>getrandmax</function>. De lo contrario,
|
|
<function>rand</function> puede devolver números aleatorios de mala
|
|
calidad.
|
|
</para>
|
|
</warning>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>srand</function></member>
|
|
<member><function>getrandmax</function></member>
|
|
<member><function>mt_rand</function></member>
|
|
<member><function>random_int</function></member>
|
|
<member><function>random_bytes</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
|
|
-->
|