< Summary - Jellyfin

Information
Class: Jellyfin.Extensions.ShuffleExtensions
Assembly: Jellyfin.Extensions
File(s): /srv/git/jellyfin/src/Jellyfin.Extensions/ShuffleExtensions.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 39
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Shuffle(...)100%11100%
Shuffle(...)100%22100%

File(s)

/srv/git/jellyfin/src/Jellyfin.Extensions/ShuffleExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3
 4namespace Jellyfin.Extensions
 5{
 6    /// <summary>
 7    /// Provides <c>Shuffle</c> extensions methods for <see cref="IList{T}" />.
 8    /// </summary>
 9    public static class ShuffleExtensions
 10    {
 11        /// <summary>
 12        /// Shuffles the items in a list.
 13        /// </summary>
 14        /// <param name="list">The list that should get shuffled.</param>
 15        /// <typeparam name="T">The type.</typeparam>
 16        public static void Shuffle<T>(this IList<T> list)
 17        {
 118            list.Shuffle(Random.Shared);
 119        }
 20
 21        /// <summary>
 22        /// Shuffles the items in a list.
 23        /// </summary>
 24        /// <param name="list">The list that should get shuffled.</param>
 25        /// <param name="rng">The random number generator to use.</param>
 26        /// <typeparam name="T">The type.</typeparam>
 27        public static void Shuffle<T>(this IList<T> list, Random rng)
 28        {
 129            int n = list.Count;
 6430            while (n > 1)
 31            {
 6332                int k = rng.Next(n--);
 6333                T value = list[k];
 6334                list[k] = list[n];
 6335                list[n] = value;
 36            }
 137        }
 38    }
 39}