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 remove white space from the beginning of a string in PHPUse the PHP ltrim() function...
How to convert php array to simple xmlIn this article, i will share with you h...
How to get the value of selected radio button in a group using jQueryUse the jQuery :checked select...
How to compare two strings in PHPUse the PHP strcmp() function...
PAN Verification In Laravel Using Sighzy APIHello, everyone some day ago we are work...