Found this nice code generator in Zen. I was thinking of creating something similar to it but would generate 4 digits for my table's int(4) primary key. Any suggestions?


////
// Create a Coupon Code. length may be between 1 and 16 Characters
// $salt needs some thought.

function zen_create_coupon_code($salt="secret", $length = SECURITY_CODE_LENGTH) {
global $db;
$ccid = md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
srand((double)microtime()*1000000); // seed the random number generator
$random_start = @rand(0, (128-$length));
$good_result = 0;
while ($good_result == 0) {
$id1=substr($ccid, $random_start,$length);
$query = "select coupon_code
from " . TABLE_COUPONS . "
where coupon_code = '" . $id1 . "'";

$rs = $db->Execute($query);

if ($rs->RecordCount() == 0) $good_result = 1;
}
return $id1;
}