mt_rand() function in PHP


The mt_rand() function is used to generate random numbers. The numbers are generated using the Mersenne Twister algorithm.

Note − This function is faster than the rand() function

Syntax

mt_rand()
or
mt_rand(min, max)

Parameters

  • min − Default is 0.The lowest number to be Returned.

  • max − The highest number to be Returned.

Return

The mt_rand() function Returns a random integer between min (or 0) and max. FALSE is Returned if max < min.

Example

 Live Demo

<?php
   echo mt_rand(100, 200);
?>

Output

144

Example

Let us see another example −

 Live Demo

<?php
   echo mt_rand();
?>

Output

132850920

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 27-Dec-2019

40 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements