Random seed is automatic as of PHP 4.2.0, and added php tags.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@129430 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2003-05-30 17:44:31 +00:00
parent edd4b864c9
commit bd220a42f3

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<!-- $Revision: 1.5 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.13 -->
<refentry id="function.array-rand">
<refnamediv>
@ -28,20 +28,24 @@
of keys for the random entries. This is done so that you can pick
random keys as well as values out of the array.
</para>
<para>
Don't forget to call <function>srand</function> to seed the random
number generator.
</para>
<note>
<para>
As of PHP 4.2.0, there is no need to seed the random number generator
with <function>srand</function>, as this is now done automatically.
</para>
</note>
<para>
<example>
<title><function>array_rand</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
srand ((float) microtime() * 10000000);
$input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand ($input, 2);
print $input[$rand_keys[0]]."\n";
print $input[$rand_keys[1]]."\n";
?>
]]>
</programlisting>
</example>