Site Owners Forums - Webmaster Forums

Site Owners Forums - Webmaster Forums (http://siteownersforums.com/index.php)
-   PHP / mySQL (http://siteownersforums.com/forumdisplay.php?f=10)
-   -   random number generator in php? (http://siteownersforums.com/showthread.php?t=65267)

noahwilson 05-31-2013 07:16 AM

random number generator in php?
 
Hello Guys,
Please help me how can i generate random number in php? please share any related script or suggest me.
Thanks for reply.

Ranjan123 10-16-2013 09:02 AM

use rand function to generate random number.

mridul 11-05-2013 11:38 PM

echo rand() . "\n";
echo rand() . "\n";

echo rand(5, 15);
?>

and u will get output like this :
7771
22264
11

softwin.swapna 03-07-2014 02:30 AM

rand() simple

azraf 03-21-2014 02:59 PM

as said above, you can use rand() function.
e.g.
$v = rand(1, 999999);
It will assign the value of $v randomly between 1 to 999999.

aleksenator 03-31-2014 12:45 PM

If you need different values. You can use simple function.

function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
srand(make_seed());
$randval = rand();
?>

guiltyCrown 04-16-2014 05:15 AM

Or for an array of randomized array

Quote:

$array = range(1,100);
shuffle($array);

kevinkrieger 05-28-2014 02:14 AM

int rand ( int $min , int $max ) function is to used to generate random number from the range.


All times are GMT -7. The time now is 10:38 PM.


Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.