Php generates a 16-bit random number with only a number and a php16 random number.

Source: Internet
Author: User

Php generates a 16-bit random number with only a number and a php16 random number.

Php generates 16-bit random numbers only

Share a php code to generate a 16-bit random number. php can generate a random number in two ways.
Method 1,

<?php$a = mt_rand(10000000,99999999);$b = mt_rand(10000000,99999999);echo $a.$b;

 

Method 2:

<? Php $ a = range (0, 9); for ($ I = 0; $ I <16; $ I ++) {$ B [] = array_rand ($ );} // www. yuju100.comvar _ dump (join ("", $ B); // result string (16) "0179571910024734"

 


A complete string of php code + html php randomly generates 10 digits, and will never be repeated, output in a single line text box

<? Php
$ Result = random (10); // generates a random number of 10 digits.
// $ Result = random (10, '123456789abcdefghijklmnpqrstuvwxyzabcdefghijklmnpqrstuvwxy'); // generate a 10-digit mixed string
Echo "<input type = 'text' size = '20' value = '{$ result}'> ";
/**
* Generate random strings
*
* @ Param int $ length output length
* @ Param string $ chars (Optional). The default value is 0123456789.
* @ Return string
*/
Function random ($ length, $ chars = '20140901 '){
$ Hash = '';
$ Max = strlen ($ chars)-1;
For ($ I = 0; $ I <$ length; $ I ++ ){
$ Hash. = $ chars [mt_rand (0, $ max)];
}
Return $ hash;
}
?>

A PHP code that generates four random numbers

A random number of four digits.
Rand)
A four-character random string that combines numbers and characters:

Function GetRandStr ($ len)
{
$ Chars = array (
"A", "B", "c", "d", "e", "f", "g", "h", "I", "j ", "k ",
"L", "m", "n", "o", "p", "q", "r", "s", "t", "u ", "v ",
"W", "x", "y", "z", "A", "B", "C", "D", "E", "F ", "G ",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q ", "R ",
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1 ", "2 ",
"3", "4", "5", "6", "7", "8", "9"
);
$ CharsLen = count ($ chars)-1;
Shuffle ($ chars );
$ Output = "";
For ($ I = 0; $ I <$ len; $ I ++)
{
$ Output. = $ chars [mt_rand (0, $ charsLen)];
}
Return $ output;
}
Echo GetRandStr (4 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.