Search
 
SCRIPT & CODE EXAMPLE
 

PHP

random number generator in php

you can use rand() function for that in php.
Example:
Generate random numbers between 1 to 50
<?php
  echo rand(1,50);
?>
Comment

php random number

rand(0,10);
or
random_int(0,10)
Comment

php random number

// $min and $max are optional
rand($min,$max);
Comment

php random integer

echo random_int(0,50);
Comment

php random number

<?php
// src/Controller/LuckyController.php
namespace AppController;

use SymfonyComponentHttpFoundationResponse;

class LuckyController
{
    public function number(): Response
    {
        $number = random_int(0, 100);

        return new Response(
            '<html><body>Lucky number: '.$number.'</body></html>'
        );
    }
}
Comment

Random Integer in php

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;
		}
Comment

php random number

rand();
Comment

assign random to a variable in PHP

<?php
function random_str_generator ($len_of_gen_str){
    $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    $var_size = strlen($chars);
    echo "Random string ="; 
    for( $x = 0; $x < $len_of_gen_str; $x++ ) {  
        $random_str= $chars[ rand( 0, $var_size - 1 ) ];  
        echo $random_str;  
    }
echo "
";
}
random_str_generator (8)
?>
Comment

PREVIOUS NEXT
Code Example
Php :: What was the old name of PHP? 
Php :: how to make primary key and foreign key in phpmyadmin 
Php :: isset php 
Php :: enable phpmailer cpanel 
Php :: assert symfony 
Php :: php functions 
Php :: string function in php 
Php :: randhex php 
Php :: view blade not found in laravel 
Php :: connect to ftp server php 
Php :: laravel, if -get() array is not emtpy 
Php :: dont insert duplicate data in laravel 
Php :: how to run a php file using 
Php :: php if statement with multiple conditions 
Php :: laravel create command tutorial 
Php :: Write Multi-Line Strings in PHP 
Php :: send email php smtp 
Php :: check if a string contains a word 
Php :: laravel email verification laravel 8 tutorial 
Php :: php .com 
Php :: flash message laravel for incorrect password 
Php :: merge multiple exceptions php 
Php :: how to add php to html 
Php :: php run cron evey hour 
Php :: function placing bet using php 
Php :: upload laravel 
Php :: custom morph relation laravel 
Php :: featured image tab not displayed on post 
Php :: do php 
Php :: cakephp 3 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =