I've been trying to set up to display a random subset of entries in a list in a weighted random manner, with each being displayed only once, and a small number of entries never being displayed.

Basically I'm trying to make a group of scripts to randomly select entries from an array, then between each selection delete every item of the array that matches it's Type. It doesn't seem to be working as it's supposed to though, any advice?
Code:
function clear_class($AdIden){
$query ="SELECT ArticleRefference, SizeClass, BusinessType FROM AdvertiserList WHERE ArticleRefference='{$AdIden}'";
$result= mysql_query($query);
$row =mysql_fetch_assoc($result);
$AdHere=$row['BusinessType'];
$AdLCount=0;
while ($AdLCount<count(AdIDListL)){
	if ($AdTypeL[$AdLCount]==$AdHere){
	unset($AdIDListL[$AdLCount]);
	unset($AdSizeL[$AdLCount]);
	}
	else{
		$AdLCount++;}
}
$AdSCount=0;
while ($AdSCount<count(AdIDListS)){
	if ($AdTypeS[$List]==$AdHere){
	unset($AdIDListS[$List]);
	unset($AdSizeS[$List]);
	}
	else{
		$AdSCount++;}
	
}
}