using LootBoxSimulator.Models.DAO; RemoteDatabaseContext databaseContext = new RemoteDatabaseContext(); var result = RandomizeRate(); var item = RandomizeItem(result); Console.WriteLine($"{item?.Name} {item?.Id}"); ItemDao? RandomizeItem(RateDao? rateDao){ if(rateDao == null) return null; var items = databaseContext.Items .Where(item => item.Rate.Id == rateDao.Id ).ToList(); if(items.Count == 0) return null; Random random = new Random(); int randomIndex = random.Next(0, items.Count); return items[randomIndex]; } RateDao? RandomizeRate() { var rates = databaseContext .Rates .OrderByDescending(item => item.Rate).ToList(); if (rates.Count == 0) return null; decimal start = 0; decimal end = rates[0].Rate; Random random = new Random(); decimal number = Convert.ToDecimal(random.NextDouble()); for (var i = 0; i < rates.Count; i++) { if (number >= start && number <= end) { Console.WriteLine($"{number} {start} {end}"); return rates[i]; } start = end; end += rates[i].Rate; } return null; }