reenadak icon

pin generate

reenadak | PRO | 02/20/18 07:00:19 PM UTC | 0 ⭐ | 305 👁️ | Never ⏰ | []
PHP |

430 B

|

None

|

0 👍

/

0 👎

    /*
    - Pin Generator
    - Generates an x-digit pin number. The pin number never starts with 0.
    - Can be converted to an integer with php's intval() function.
    
    $length     - The amount of digits the pin number should have.
    */
    
    public function generatePin($length = 4) {
        $pin = '';
        
        for ($i = 0; $i < $length; $i++) {
            if ($i == 0)
                $pin .= rand(1, 9);
            else
                $pin .= rand(0, 9);
        }
        
        return $pin;
    }

Comments