Skip to content

The Free Software Media System - Server Backend & API

Merge remote-tracking branch 'upstream/master' into random

Bond-009a2c35e6dba02
diff --cc MediaBrowser.Common/Extensions/ShuffleExtensions.cs
index 0000000000,0000000000..5889d09c4b
new file mode 100644
--- /dev/null
+++ b/MediaBrowser.Common/Extensions/ShuffleExtensions.cs
@@@ -1,0 -1,0 +1,31 @@@
++using System;
++using System.Collections.Generic;
++
++namespace MediaBrowser.Common.Extensions
++{
++ /// <summary>
++ /// Provides <c>Shuffle</c> extensions methods for <see cref="IList{T}" />.
++ /// </summary>
++ public static class ShuffleExtensions
++ {
++ private static readonly Random _rng = new Random();
++
++ /// <summary>
++ /// Shuffles the items in a list.
++ /// </summary>
++ /// <param name="list">The list that should get shuffled.</param>
++ /// <typeparam name="T">The type.</typeparam>
++ public static void Shuffle<T>(this IList<T> list)
++ {
++ int n = list.Count;
++ while (n > 1)
++ {
++ n--;
++ int k = _rng.Next(n + 1);
++ T value = list[k];
++ list[k] = list[n];
++ list[n] = value;
++ }
++ }
++ }
++}