#nullable enable
using System;
using System.Collections.Generic;
namespace MediaBrowser.Common.Extensions
{
///
/// Provides Shuffle extensions methods for .
///
public static class ShuffleExtensions
{
private static readonly Random _rng = new Random();
///
/// Shuffles the items in a list.
///
/// The list that should get shuffled.
/// The type.
public static void Shuffle(this IList list)
{
list.Shuffle(_rng);
}
///
/// Shuffles the items in a list.
///
/// The list that should get shuffled.
/// The random number generator to use.
/// The type.
public static void Shuffle(this IList list, Random rng)
{
int n = list.Count;
while (n > 1)
{
int k = rng.Next(n--);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
}
}