public Option <MediaItem> Peek(int offset)
    {
        if (offset == 0)
        {
            return(Current);
        }

        if ((State.Index + offset) % _mediaItemCount == 0)
        {
            IList <MediaItem>  shuffled;
            Option <MediaItem> tail = Current;

            // clone the random
            CloneableRandom randomCopy = _random.Clone();

            do
            {
                int newSeed = randomCopy.Next();
                randomCopy = new CloneableRandom(newSeed);
                shuffled   = Shuffle(_mediaItems, randomCopy);
            } while (_mediaItems.Count > 1 && shuffled[0] == tail);

            return(shuffled.Any() ? shuffled[0] : None);
        }

        return(_shuffled.Any() ? _shuffled[(State.Index + offset) % _mediaItemCount] : None);
    }
Beispiel #2
0
    public ProgramScheduleItem Peek(int offset)
    {
        if (offset == 0)
        {
            return(Current);
        }

        if ((State.Index + offset) % _scheduleItemsCount == 0)
        {
            IList <ProgramScheduleItem> shuffled;
            ProgramScheduleItem         tail = Current;

            // clone the random
            CloneableRandom randomCopy = _random.Clone();

            do
            {
                int newSeed = randomCopy.Next();
                randomCopy = new CloneableRandom(newSeed);
                shuffled   = Shuffle(_scheduleItems, randomCopy);
            } while (_scheduleItems.Count > 1 && shuffled[0] == tail);

            return(shuffled[0]);
        }

        return(_shuffled[(State.Index + offset) % _scheduleItemsCount]);
    }
Beispiel #3
0
    public CloneableRandom Clone()
    {
        var clone = new CloneableRandom(_seed);

        for (var i = 0; i < _count; i++)
        {
            clone.Next();
        }

        return(clone);
    }
    private IList <MediaItem> Shuffle(IEnumerable <GroupedMediaItem> list, CloneableRandom random)
    {
        GroupedMediaItem[] copy = list.ToArray();

        int n = copy.Length;

        while (n > 1)
        {
            n--;
            int k = random.Next(n + 1);
            (copy[k], copy[n]) = (copy[n], copy[k]);
        }

        return(GroupedMediaItem.FlattenGroups(copy, _mediaItemCount));
    }
Beispiel #5
0
    private IList <ProgramScheduleItem> Shuffle(IEnumerable <ProgramScheduleItem> list, CloneableRandom random)
    {
        ProgramScheduleItem[] copy = list.ToArray();

        int n = copy.Length;

        while (n > 1)
        {
            n--;
            int k = random.Next(n + 1);
            (copy[k], copy[n]) = (copy[n], copy[k]);
        }

        return(copy);
    }
    public void MoveNext()
    {
        if ((State.Index + 1) % _mediaItemCount == 0)
        {
            Option <MediaItem> tail = Current;

            State.Index = 0;
            do
            {
                State.Seed = _random.Next();
                _random    = new CloneableRandom(State.Seed);
                _shuffled  = Shuffle(_mediaItems, _random);
            } while (_mediaItems.Count > 1 && Current == tail);
        }
        else
        {
            State.Index++;
        }

        State.Index %= _mediaItemCount;
    }
Beispiel #7
0
    public void MoveNext()
    {
        if ((State.Index + 1) % _scheduleItemsCount == 0)
        {
            ProgramScheduleItem tail = Current;

            State.Index = 0;
            do
            {
                State.Seed = _random.Next();
                _random    = new CloneableRandom(State.Seed);
                _shuffled  = Shuffle(_scheduleItems, _random);
            } while (_scheduleItems.Count > 1 && Current == tail);
        }
        else
        {
            State.Index++;
        }

        State.Index %= _scheduleItemsCount;
    }