<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >rand</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Mathematical Functions" HREF="ref.math.html"><LINK REL="PREVIOUS" TITLE="rad2deg" HREF="function.rad2deg.html"><LINK REL="NEXT" TITLE="round" HREF="function.round.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.rad2deg.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.round.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.rand" ></A >rand</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN50885" ></A ><P > (PHP 3, PHP 4 , PHP 5)</P >rand -- Generate a random integer</DIV ><DIV CLASS="refsect1" ><A NAME="AEN50888" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >rand</B > ( [int min, int max])<BR ></BR ><P > If called without the optional <VAR CLASS="parameter" >min</VAR >, <VAR CLASS="parameter" >max</VAR > arguments <B CLASS="function" >rand()</B > returns a pseudo-random integer between 0 and <TT CLASS="constant" ><B >RAND_MAX</B ></TT >. If you want a random number between 5 and 15 (inclusive), for example, use <VAR CLASS="literal" >rand (5, 15)</VAR >. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN50906" ></A ><P ><B >Exemplu 1. <B CLASS="function" >rand()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">echo </font><font color="#0000BB">rand</font><font color="#007700">() . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br />echo </font><font color="#0000BB">rand</font><font color="#007700">() . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br />echo </font><font color="#0000BB">rand</font><font color="#007700">(</font><font color="#0000BB">5</font><font color="#007700">, </font><font color="#0000BB">15</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P > The above example will output something similar to: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >7771 22264 11</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > On some platforms (such as Windows) <TT CLASS="constant" ><B >RAND_MAX</B ></TT > is only 32768. If you require a range larger than 32768, specifying <VAR CLASS="parameter" >min</VAR > and <VAR CLASS="parameter" >max</VAR > will allow you to create a range larger than RAND_MAX, or consider using <A HREF="function.mt-rand.html" ><B CLASS="function" >mt_rand()</B ></A > instead. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B >As of PHP 4.2.0, there is no need to seed the random number generator with <A HREF="function.srand.html" ><B CLASS="function" >srand()</B ></A > or <A HREF="function.mt-srand.html" ><B CLASS="function" >mt_srand()</B ></A > as this is now done automatically. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > In versions before 3.0.7 the meaning of <VAR CLASS="parameter" >max</VAR > was <VAR CLASS="parameter" >range</VAR >. To get the same results in these versions the short example should be <VAR CLASS="literal" >rand (5, 11)</VAR > to get a random number between 5 and 15. </P ></BLOCKQUOTE ></DIV ><P > See also: <A HREF="function.srand.html" ><B CLASS="function" >srand()</B ></A >, <A HREF="function.getrandmax.html" ><B CLASS="function" >getrandmax()</B ></A >, and <A HREF="function.mt-rand.html" ><B CLASS="function" >mt_rand()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.rad2deg.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.round.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >rad2deg</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.math.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >round</TD ></TR ></TABLE ></DIV ></BODY ></HTML >