Ok, I'm trying to generate a random number I have a set of functions to do this and check the DB for duplicate entries! below are the fuction but i'm get invalid range on the rand() bit? anyone know why?
Also can you use a $global element for a mysql DB connection? if not is there a better way to use mysql in function with out doing a db connect in all function?
Thanks
Ashley
// Makes seed for a random number
function make_seed() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
// Test ident is valid
function valid_ident($val){
$db = mysql_connect("195.224.9.42","coldseal","fishmonger");
mysql_select_db("pvc",$db);
$sql = mysql_query("select * from uid where uid='$val'", $GLOBAL[db]);
$many = mysql_num_rows($sql);
mysql_close();
return $many;
}
// makes randow id number
function get_ident(){
srand(make_seed());
$randval = rand(1000000000, 9999999999);
$valid = valid_ident($randval);
if($valid == "1"){
$ident = get_ident();
}else{
$ident = $randval;
}
return $ident;
}