Php random number 10 digits
Show
rand() or mt_rand() functions can be used to Generate 10 Digit Random Number in PHP. Examples given below show how to Generate 10 Digit number using rand and mt_rand functions. Generate 10 Digit Random Number using rand()To Generate 10 Digit number using rand() function, we will define the lowest number and highest number as it's parameters. The rand() function will return a random integer between min and max numbers (including min and max numbers). Syntax of rand()The syntax of rand() function is given below.
Example 1
Output2387509223 Generate 10 Digit Random Number using mt_rand()mt_rand() function is just like rand() function but it is 4 times faster than rand() function. To use mt_rand() function, define min and max numbers. The mt_rand() function will return a random integer between min and max numbers (including min and max numbers). Syntax of mt_rand()The syntax of mt_rand() function is given below.
The mt_rand() returns false if second number is smaller than first one. Example 2
Output7128830561 Also Read:Generate 1 Digit Random Number in PHP I am trying to generate a random 10 digit number and insert this into mysql on page load, so each time the page refreshes or loads there should be a different 10 digit number being inserted into the database, however at the moment it just keeps inserting the same 10 digit number again and again. Can someone please show me where I am going wrong? Thanks.
This is the number I am constantly getting: 2147483647
asked Apr 29, 2014 at 11:07
4 try to getting ten digit rand no
answered Apr 29, 2014 at 11:11
Rakesh SharmaRakesh Sharma 13.6k4 gold badges36 silver badges42 bronze badges 3 You need to change column type. The number that you try to insert is higher than column maximum value (in your case SIGNED INT - 2147483647)
answered Apr 29, 2014 at 11:21
You're getting Just use a string with a loop and the
DEMO answered Apr 29, 2014 at 11:16
h2oooooooh2ooooooo 38.2k8 gold badges65 silver badges101 bronze badges You can also try this if you want. Its not generating a random number but a random string
Downvoting not required!!! Thx answered Apr 29, 2014 at 11:31
ProfessorProfessor 6094 silver badges20 bronze badges You should consider using the In your code, you are not using the full 10 digit number range, try something like
answered Apr 29, 2014 at 11:17
KamiKami 18.8k4 gold badges49 silver badges63 bronze badges Use this code.
answered Apr 29, 2014 at 11:09
1 Use php mt_rand() function instead of rand()
answered Apr 29, 2014 at 11:13
dkakotidkakoti 6028 silver badges25 bronze badges
answered Apr 29, 2014 at 11:14
There is no problem with your number generating code. Try unsetting your variables before they are defined and see if it fixes the problem.
You could just as easily use the answered Apr 29, 2014 at 11:19
When I run your script I get different numbers everytime. Why don't you use the uniqid() function ?
Reporter 3,7965 gold badges31 silver badges46 bronze badges answered Apr 29, 2014 at 11:16
0 Here is the simple way of generating 10 digit random number
answered Jul 25, 2015 at 11:56
It is the most suitable method to remember that when you did generate this key/number
its 10 digit number that convert this into exact date and time. answered Jan 5 at 10:39
Not the answer you're looking for? Browse other questions tagged php mysql or ask your own question.How do I generate a random 10 digit number in PHP?The rand() function generates a random integer. Example tip: If you want a random integer between 10 and 100 (inclusive), use rand (10,100). Tip: As of PHP 7.1, the rand() function has been an alias of the mt_rand() function.
How do you generate a random 10 digit number in Python?import random n = random. random() print(n). import random n = random. randint(0,22) print(n). import random randomlist = [] for i in range(0,5): n = random. randint(1,30) randomlist. ... . import random #Generate 5 random numbers between 10 and 30 randomlist = random. sample(range(10, 30), 5) print(randomlist). What is Mt_rand function in PHP?The mt_rand() function is a drop-in replacement for the older rand(). It uses a random number generator with known characteristics using the » Mersenne Twister, which will produce random numbers four times faster than what the average libc rand() provides.
How do I generate a random 10 digit number in C#?Would nine zeros followed by a 1 be valid for you? ... . Thanks, I found this a helpful reference. ... . Random random = new Random(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10; i++) { sb.Append(random.Next(0, 9).ToString()); } return sb.ToString(); ... . 1) What are you using this number for?. |