When you need to save multiple files in same directory, then you need to generate random number everytime. Generating random numbers in PHP can be done by many ways.
In this article, we will discuss built-in functions which can be used to generate random numbers in PHP.
The rand() function generates a random integer value.
<?php echo(rand()); // 14870
If you want to get values between two digits, include these parameters. Suppose you want random number between 100 and 1000, pass them in function arguments.
<?php echo(rand(100, 1000)); // 458
Generate random number using the Mersenne Twister Random number generator. This is four times faster and more secure than rand() function.
<?php echo mt_rand(); // 14314917
mt_rand() function also accepts two arguments, minimum and maximum integer value. It will return integer number between minimum and miximum number.
<?php echo mt_rand(100, 1000); // 752
random_int() function generates cryptographically secured pseudo-random integer number.
<?php echo(random_int(100, 1000)); // 459 echo(random_int(-1000, -100)); // -121
I hope it will help you.
How to Detect a Mobile Device in jQueryUse the JS matchMedia() Method You ca...
How to Remove Duplicate Values from an Array in PHPIn this article, i will share with you h...
How to Convert a Date from yyyy-mm-dd to dd-mm-yyyy Format in PHPUse the strtotime() Function You can...