PHP mt rand

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : mt_rand() function

Description

The mt_rand() function is used to generate a random integer using the Mersenne Twister algorithm.

Version

(PHP 4 and above)

Syntax

mt_rand()

mt_rand( minv, maxv )

Parameters

Name

Description

Required /
Optional

Type

minv

Lowest value to be returned.
Default : 0

Optional

Integer

maxv

Highest value to be returned.
Default : mt_getrandmax())

Optional

Integer

Note : If the function is called without the minv and maxv arguments mt_rand() returns a pseudo-random value between 0 and mt_getrandmax(). If you want a random number between 10 and 15 (inclusive), for example, use mt_rand(10, 15).

Return value

A random number value between minv (or 0) and maxv.

Value Type : Integer.

Example :

  1. echo(mt_rand() . "
    ");  

  2. echo(mt_rand(10,15))  

  3. ?>