コード例 #1
0
        private static void TestShuffleAlgorithm(IShuffleAlgorithm algo, bool forward)
        {
            for (int i = 1; i < 1000; i++)
            {
                var checkNumbers = new BitArray(i, false);

                algo.Length = i;
                algo.Seed   = i;

                for (int j = 0; j < i; j++)
                {
                    if (forward)
                    {
                        algo.Next();
                    }
                    else
                    {
                        algo.Prev();
                    }
                    int shufNum = algo.Index;
                    if (checkNumbers.Get(shufNum))
                    {
                        Assert.Fail("Duplicate number");
                    }
                    checkNumbers.Set(shufNum, true);
                }
            }
        }
コード例 #2
0
        private PlaylistItem NPMove(sbyte off)
        {
            if (freeList.Count == 0)
            {
                return(null);
            }
            indexCount += Math.Sign(off);

            if (Loop)
            {
                indexCount = Util.MathMod(indexCount, freeList.Count);
            }
            else if (indexCount < 0 || indexCount >= freeList.Count)
            {
                indexCount = Math.Max(indexCount, 0);
                indexCount = Math.Min(indexCount, freeList.Count);
                return(null);
            }

            if (Random)
            {
                if (dataSetLength != freeList.Count)
                {
                    dataSetLength  = freeList.Count;
                    shuffle.Length = dataSetLength;
                }
                if (off > 0)
                {
                    shuffle.Next();
                }
                if (off < 0)
                {
                    shuffle.Prev();
                }
            }

            if (Index < 0)
            {
                return(null);
            }
            var entry = freeList.GetResource(Index);

            if (entry == null)
            {
                return(null);
            }
            entry.Meta.FromPlaylist = true;
            return(entry);
        }