diff options
| author | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-03-10 22:45:17 +0100 |
|---|---|---|
| committer | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-03-10 22:45:17 +0100 |
| commit | 6131599e8808a6cdddba8ce0da82107cc662ae1c (patch) | |
| tree | a43499ea871b5770465c0938a2bc20ae923a4d2d /MediaBrowser.Common/Extensions/ShuffleExtensions.cs | |
| parent | 76957213e601e8f03c9975707d5e0a22b899207b (diff) | |
| parent | 97bca5a9008ba94411c45572e690decc58805b85 (diff) | |
Merge branch 'master' into support-injecting-iconfiguration
Diffstat (limited to 'MediaBrowser.Common/Extensions/ShuffleExtensions.cs')
| -rw-r--r-- | MediaBrowser.Common/Extensions/ShuffleExtensions.cs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/MediaBrowser.Common/Extensions/ShuffleExtensions.cs b/MediaBrowser.Common/Extensions/ShuffleExtensions.cs index 5889d09c4..0432f36b5 100644 --- a/MediaBrowser.Common/Extensions/ShuffleExtensions.cs +++ b/MediaBrowser.Common/Extensions/ShuffleExtensions.cs @@ -17,11 +17,22 @@ namespace MediaBrowser.Common.Extensions /// <typeparam name="T">The type.</typeparam> public static void Shuffle<T>(this IList<T> list) { + list.Shuffle(_rng); + } + + /// <summary> + /// Shuffles the items in a list. + /// </summary> + /// <param name="list">The list that should get shuffled.</param> + /// <param name="rng">The random number generator to use.</param> + /// <typeparam name="T">The type.</typeparam> + public static void Shuffle<T>(this IList<T> list, Random rng) + { int n = list.Count; while (n > 1) { n--; - int k = _rng.Next(n + 1); + int k = rng.Next(n + 1); T value = list[k]; list[k] = list[n]; list[n] = value; |
