Esempio n. 1
0
    public static T GetNextNonRepeatingRandom()
    {
        var nonrepeaters = _cache
                           .Except(_memory);
        // Not familar with unity.. but this should make
        // sense what I am doing
        var next = nonrepeaters.ElementAt(UnityEngine.Random(0, nonrepeaters.Count() - 1));

        // this fast, Stack will know it's count so no GetEnumerator()
        // and _cache List is the same (Count() will call List.Count)
        if (_memory.Count > _cache.Count() / 2)
        {
            _memory.Pop();
        }
        _memory.Push(next);
        return(next);
    }