public static IList <SongRandomizerResult> GetRandomSongs(int count, PlaylistManager playlistManager, HashSet <string> playlistSubset = null)
        {
            // Get total number of songs from all selected playlists
            var numSongs            = 0;
            var playlistsUnfiltered = playlistManager.GetAvailablePlaylists();
            var playlists           = new List <PlaylistInfo>();

            foreach (var playlist in playlistsUnfiltered)
            {
                if (playlistSubset != null && !playlistSubset.Contains(playlist.Id))
                {
                    continue;
                }

                playlists.Add(playlist);
                numSongs += playlist.SongCount;
            }

            var randomSongs = new List <SongRandomizerResult>();

            for (var i = 0; i < count; i++)
            {
                // Draw random song number
                var songIndex = Random.Next(0, numSongs);

                // Find the randomized song
                var infoOpt = FindSong(songIndex, playlists);
                if (!infoOpt.Ok)
                {
                    throw new CommandException("SongRandomizer: Could not find the song at index " + songIndex + ".", CommandExceptionReason.InternalError);
                }

                var(list, index) = infoOpt.Value;
                var(playlist, _) = playlistManager.GetPlaylist(list.Id).UnwrapThrow();

                if (playlist.Count != list.SongCount)
                {
                    Log.Warn("SongRandomizer: Playlist '{0}' is possibly corrupted!", list.Id);
                }

                var result = new SongRandomizerResult(list.Id, index, playlist[index]);
                if (randomSongs.Contains(result) && numSongs > count)
                {
                    Log.Trace("SongRandomizer: Ignored duplicate song.");
                    i--;
                }
                else
                {
                    randomSongs.Add(result);
                }
            }

            return(randomSongs);
        }
 protected bool Equals(SongRandomizerResult other)
 {
     return(PlaylistId == other.PlaylistId && IndexInPlaylist == other.IndexInPlaylist);
 }