martes, 30 de septiembre de 2014

Generate Random 10 Digit Number in PHP

Generate Random 10 Digit Number in PHP
PHP, Quick Tips 40 Comments

The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
  
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);

Here’s whats happening with the code:

The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.

The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.

Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.


- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

Generate Random 10 Digit Number in PHP

PHP, Quick Tips 40 Comments
The application I’m developing requires a random 10 digit number as a bar code on season pass. A simple way to create a unique number is to use the following code:
?
1
$random = substr(number_format(time() * mt_rand(),0,'',''),0,10);
Here’s whats happening with the code:
The outer portion “substr” is used to chop down the random number we create to 10 characters. You will notice the number 10 at the end of the snippet, which can be changed to any number you want.
The “number_format” function helps get rid of the scientific notation that will arise from generating the random number. In the middle, “time()” and “mt_rand()” are multiplied. Time() is the number of seconds from January 1 1970, and rand() is a uniquely generated number through PHP.
Always remember that generating unique numbers is not fool proof.  If your application requires each number to be unique, perform a collision check in the database before saving.
- See more at: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/#sthash.WrvYJJBc.dpuf

No hay comentarios:

Publicar un comentario