if the number of exisiting subscribers (used as caller/callee
in created cdrs) is low, there is a higher risk that it can
fail to randomize one.
Change-Id: Id8f37f259e07f1b50251008a207a3e6122a628ea
die("less than 2 subscriber to randomize")if($max_id-$min_id)<2;
my$rand=$min_id+int(rand($max_id-$min_id)+0.5);
if(defined$excluding_id){
while($rand==$excluding_id){
$rand=$min_id+int(rand($max_id-$min_id)+0.5);
}
}
my$stmt='SELECT r1.* FROM '.$table.' AS r1'.
' JOIN (SELECT ? AS id) AS r2';
my$stmt='SELECT r1.* FROM '.$table.' AS r1';
my@params=();
push(@params,$rand);
if($reseller_id){
$stmt.=' INNER JOIN '.$db->tableidentifier(NGCP::BulkProcessor::Dao::Trunk::billing::contracts::gettablename()).' AS contract ON r1.contract_id = contract.id'.
' INNER JOIN '.$db->tableidentifier(NGCP::BulkProcessor::Dao::Trunk::billing::contacts::gettablename()).' AS contact ON contract.contact_id = contact.id';