public static AD randomAD(List <AD> ADS, DB db) { if (ADS.Count == 0) { return(null); } Random random = new Random(); int ID = random.Next(ADS.First().ID, ADS.Last().ID + 1); AD ad = db.ADS.Find(ID); if (ad == null) { return(randomAD(ADS, db)); } else if (ADS.Contains(ad) == false) { return(randomAD(ADS, db)); } else if (ISVALID(ad) == false) { ADS.Remove(ad); return(randomAD(ADS, db)); } else { db.ADWatch(ad.ID); return(ad); } }