示例#1
0
        private static List <int> GenerateTimedData(
            int requests,
            int numTicks,
            Noise noise)
        {
            List <int> data = noise
                              .CalculateNextValues(numTicks)
                              .Select(value => (int)value)
                              .ToList();

            var rawSum = data.Sum();
            var ratio  = requests / (float)rawSum;

            int processedSum = 0;

            for (int i = 0; i < data.Count(); i++)
            {
                data[i]       = (int)(data[i] * ratio);
                processedSum += data[i];
            }

            var requestDelta = requests - processedSum;

            var div = requestDelta / data.Count;
            var mod = requestDelta % data.Count;

            for (int i = 0; i < data.Count; i++, mod--)
            {
                data[i] += div + (mod > 0 ? 1 : 0);

                if (div == 0 && mod == 0)
                {
                    break;
                }
            }

            return(data);
        }