예제 #1
0
        /// <summary>
        /// Implementation of the Fisher-Yates shuffle.
        /// Shuffles the list in place.
        /// </summary>
        public static void Shuffle <T>(this T list) where T : IList
        {
            var size = list.Count;

            for (var i = 0; i < size - 2; i++)
            {
                var j     = StrongRandom.Next(i, size);
                var value = list[i];
                list[i] = list[j];
                list[j] = value;
            }
        }
예제 #2
0
        public GameCode Get()
        {
            lock (_sync)
            {
                if (_codes.Count == 0)
                {
                    _logger.LogWarning("Boot.Codes: Ran out of codes!");
                    return(_codeFactory.Create());
                }

                var index = StrongRandom.Next(0, _codes.Count);
                var code  = _codes[index];

                _codes.RemoveAt(index);
                _inUse.Add(code);

                return(code);
            }
        }