Generate a random string PHP
<p>For generating random string i written code like this But if the function is called with a negative value, or zero, or 1 million it will create lot of problems. So please suggest me better code.</p>

<pre><code>/*
* The following function is for generating a random string value.
* @param unknown_type $length
* @return string $randString
*/
function generateRandomString( $length ) {
    $randString = "";
    srand();
    $characters = "abcdefghijklmnopqrstuvwxyz1234567890";
    /*
    *   build string of random characters
    */ 
    while( strlen( $randString ) &lt; $length ) {
        $randString .= substr( $characters, rand() % (strlen( $characters )),1 );
    }
return $randString;
}
</code></pre>
