Advertisement
reenadak

pin generate

Feb 20th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.43 KB | None | 0 0
  1.     /*
  2.     - Pin Generator
  3.     - Generates an x-digit pin number. The pin number never starts with 0.
  4.     - Can be converted to an integer with php's intval() function.
  5.    
  6.     $length     - The amount of digits the pin number should have.
  7.     */
  8.    
  9.     public function generatePin($length = 4) {
  10.         $pin = '';
  11.        
  12.         for ($i = 0; $i < $length; $i++) {
  13.             if ($i == 0)
  14.                 $pin .= rand(1, 9);
  15.             else
  16.                 $pin .= rand(0, 9);
  17.         }
  18.        
  19.         return $pin;
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement