If you have a web application and wanted to add functionality to generate random keys or password for your users, this little function will help you. It will also allow you to include special characters by giving the $alphanumeric parameter a false value.

<?php
function get_random_str( $length = 12, $alphanumeric = true ) {
    $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    if( !$alphanumeric ) {
        $alphabet .= '!@#$%^&*()-_[]{}<>~`+=,.;:/?|';
    }
    $str = '';
    $alphaLength = strlen($alphabet) - 1;
    for ($i = 0; $i < $length; $i++) {
        $n = rand(0, $alphaLength);
        $str .= $alphabet[$n];
    }
    return $str;
}

//generate a 16 characters password
$random = get_random_str(16, false);

echo $random;