Return to Snippet

Revision: 30493
at August 15, 2010 12:57 by jjjrmy


Initial Code
function genRandomString($length) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $string = '';    
    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}

//////////////////////////////////////
// Example :                        //
//                                  //
// echo genRandomString(rand(3,7)); //
//                                  //
// Could Print Out: Ac1dF           //

//////////////////////////////////////

Initial URL


Initial Description
I didn't make this, I just found it online and found it really useful for generating unique IDs for stuff.

Have fun using this.

Initial Title
Generate Random String

Initial Tags


Initial Language
PHP