Answered by : ankur-prajapati
you can use rand() function for that in php.
Example:
Generate random numbers between 1 to 50
<?php echo rand(1,50);
?>
Source : | Last Update : Sat, 18 Jul 20
Answered by : -n746j61qvtgj
rand(0,10);
or
random_int(0,10)
Source : | Last Update : Sat, 10 Oct 20
Answered by : iamatp-on-scratch
<?php #The rand() function generates a random number: echo(rand()); #Picks a random number from anywhere to anywhere echo(rand(0, 10)); #Picks a random number from 0 to 10
<?
Source : | Last Update : Sat, 18 Jun 22
Answered by : mattia-consiglio
// $min and $max are optional
rand($min,$max);
Source : https://www.php.net/manual/en/function.rand.php | Last Update : Tue, 21 Apr 20
Answered by : -n746j61qvtgj
echo random_int(0,50);
Source : | Last Update : Sat, 10 Oct 20
Answered by : atsu-emmanuel-terungwa
<?php echo rand(1,50);
?>
Source : | Last Update : Sun, 02 Aug 20
Answered by : jarno-looij
<?php
// src/Controller/LuckyController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
class LuckyController
{ public function number(): Response { $number = random_int(0, 100); return new Response( '<html><body>Lucky number: '.$number.'</body></html>' ); }
}
Source : https://symfony.com/doc/current/page_creation.html | Last Update : Wed, 06 Apr 22
Answered by : joa
mt_rand(1000, 9999)
Source : | Last Update : Fri, 23 Apr 21
Answered by : nilesh
function genrateRandomInteger($len = 10) { $last =-1; $code = ''; for ($i=0;$i<$len;$i++) { do { $next_digit=mt_rand(0,9); } while ($next_digit == $last); $last=$next_digit; $code.=$next_digit; } return $code; }
Source : | Last Update : Mon, 03 Jan 22
Answered by : eric-tam
<?php
echo random(1, 100); //returns a random number between 1 to 100.
?>
Source : | Last Update : Sun, 10 Jul 22