public Task <uint> GetRandomSongID(CancellationToken cancellation) { var weights = this.voteCache.AllSongs.ToDictionary( keySelector: summary => summary, elementSelector: summary => Math.Max(summary.VoteSum, 0)); if (weights.Count == 0) { return(Task.FromResult(0u)); } cancellation.ThrowIfCancellationRequested(); var weightedRandom = new WeightedRandom <SongSummary>(weights); cancellation.ThrowIfCancellationRequested(); return(Task.FromResult(weightedRandom.GetRandom(ThreadSafeRandom.Instance).Song.ID)); }
public RandomSongProviderCombinator(WeightedRandom <IRandomSongProvider> providers, ILogger <RandomSongProviderCombinator> logger) { this.providers = providers; this.logger = logger; }