もう少し堅牢で機能を追加したものが必要だと判断しました。これが私が思いついたものです。
/**
* Hash Gen
* @author Kyle Coots
* @version 1.0
* Allow you to create a unique hash with a maximum value of 32.
* Hash Gen uses phps substr, md5, uniqid, and rand to generate a unique
* id or hash and allow you to have some added functionality.
*
* @see subtr()
* @see md5()
* @see uniqid()
* @see rand()
*
* You can also supply a hash to be prefixed or appened
* to the hash. hash[optional] is by default appened to the hash
* unless the param prefix[optional] is set to prefix[true].
*
* @param start[optional]
* @param end[optional]
* @param hash[optional]
* @param prefix bool[optional]
*
* @return string a unique string max[32] character
*/
function hash_gen($start = null, $end = 0, $hash = FALSE, $prefix = FALSE){
// start IS set NO hash
if( isset($start, $end) && ($hash == FALSE) ){
$md_hash = substr(md5(uniqid(rand(), true)), $start, $end);
$new_hash = $md_hash;
}else //start IS set WITH hash NOT prefixing
if( isset($start, $end) && ($hash != FALSE) && ($prefix == FALSE) ){
$md_hash = substr(md5(uniqid(rand(), true)), $start, $end);
$new_hash = $md_hash.$hash;
}else //start NOT set WITH hash NOT prefixing
if( !isset($start, $end) && ($hash != FALSE) && ($prefix == FALSE) ){
$md_hash = md5(uniqid(rand(), true));
$new_hash = $md_hash.$hash;
}else //start IS set WITH hash IS prefixing
if( isset($start, $end) && ($hash != FALSE) && ($prefix == TRUE) ){
$md_hash = substr(md5(uniqid(rand(), true)), $start, $end);
$new_hash = $hash.$md_hash;
}else //start NOT set WITH hash IS prefixing
if( !isset($start, $end) && ($hash != FALSE) && ($prefix == TRUE) ){
$md_hash = md5(uniqid(rand(), true));
$new_hash = $hash.$md_hash;
}else{
$new_hash = md5(uniqid(rand(), true));
}
return $new_hash;
}