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.
rand($min, $max)
<?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.
mt_rand($min, $max)
<?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.
random_int($min, $max)
<?php
echo(random_int(100, 1000)); // 459
echo(random_int(-1000, -100)); // -121
I hope it will help you.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to remove white space from the beginning of a string in PHP
Use the PHP ltrim() function...How to convert php array to simple xml
In this article, i will share with you h...How to get the value of selected radio button in a group using jQuery
Use the jQuery :checked select...How to compare two strings in PHP
Use the PHP strcmp() function...PAN Verification In Laravel Using Sighzy API
Hello, everyone some day ago we are work...