예제 #1
0
        public void FailsWhenFirstArgIsNull()
        {
            var         rng = new Random();
            IList <int> a   = null;

            Assert.Throws <ArgumentNullException>(() => ShuffleOps.ShuffleInPlace(a, rng));
        }
예제 #2
0
        public void FailsWhenSecondArgIsNull()
        {
            Random rng = null;
            var    a   = new List <int> {
                1, 2, 3, 4, 5, 6
            };

            Assert.Throws <ArgumentNullException>(() => ShuffleOps.ShuffleInPlace(a, rng));
        }
예제 #3
0
        public void ReadmeExampleWorks()
        {
            var rng = new Random(Seed: 5);
            var a   = new List <int> {
                1, 2, 3, 4, 5, 6
            };

            ShuffleOps.ShuffleInPlace(a, rng);
            Assert.Equal(new[] { 6, 1, 4, 5, 2, 3 }, a);
        }
예제 #4
0
        private static void Example1()
        {
            var rng = new Random(Seed: 5);
            var a   = new List <int> {
                1, 2, 3, 4, 5, 6
            };

            ShuffleOps.ShuffleInPlace(a, rng);
            Console.WriteLine(string.Join(", ", a));
        }
예제 #5
0
 /// <summary>Shuffles a <see cref="IList{T}"/>.</summary>
 /// <typeparam name="T">Type of items in <paramref name="list"/>.</typeparam>
 /// <param name="source">The random number generator to use.</param>
 /// <param name="list">The list to shuffle.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="list"/> is null - or <paramref name="source"/> is null.</exception>
 public static void Shuffle <T>(this Random source, IList <T> list)
 => ShuffleOps.ShuffleInPlace(list, source);