Beispiel #1
0
        public static (string[], bool) GetStringArrayLines(string[] _String, int _StartLine = 0, int _EndLine = -1)
        {
            string[] lines    = _String;
            int      lastLine = 0;

            if (lines.Length < 1)
            {
                HEVConsole.Print("GetStringArrayLines() Empty string array.", EPrintType.eError);
                return(lines, false);
            }
            lastLine = lines.Length - 1;
            if (_StartLine == 0 && _EndLine == -1)
            {
            }
            else if (_StartLine == -1)
            {
                lines = new string[] { lines[lastLine] };
            }
            else
            {
                int startLine = HEVMath.Max(_StartLine, 0);
                startLine = HEVMath.Min(startLine, lastLine);
                int endLine = HEVMath.Min(_EndLine, lastLine);
                endLine = HEVMath.Max(_StartLine, _EndLine);
                List <string> linesList = new List <string>();
                for (int i = startLine; i < endLine; i++)
                {
                    linesList.Add(lines[i]);
                }
                lines = linesList.ToArray();
            }
            return(lines, true);
        }
Beispiel #2
0
        public static int CryptoRandomInt(int _Min, int _Max)
        {
            byte[] randomNumber = new byte[1];
            CryptoGenerator.GetBytes(randomNumber);

            double asciiValueOfRandomCharacter = Convert.ToDouble(randomNumber[0]);
            double multiplier         = HEVMath.Max(0, (asciiValueOfRandomCharacter / 255d) - 0.00000000001d);
            int    range              = _Max - _Min + 1;
            double randomValueInRange = HEVMath.Floor(multiplier * range);

            return((int)(_Min + randomValueInRange));
        }
Beispiel #3
0
        public static bool TryParse(string _String, out int _Result, bool _Clamp = false, int _Min = 0, int _Max = 9999)
        {
            int value = -1;

            if (!Validate(_String))
            {
                _Result = value; return(false);
            }
            string str = _String.ToLower();

            if (!int.TryParse(str, out value))
            {
                _Result = value; return(false);
            }

            if (_Clamp)
            {
                int min = HEVMath.Min(_Min, _Max);
                int max = HEVMath.Max(_Min, _Max);
                if (min == max)
                {
                    value = max;
                }
                else
                {
                    value = HEVMath.Clamp(value, min, max);
                }
            }
            _Result = value;
            return(true);

            /* Sensitive
             * if ( HEVMath.Validate( _Min, _Max, value ) ) {
             *      _Result = value;
             *      return true;
             * } else {
             *      value = Math.Clamp( value, _Min, _Max );
             *      _Result = value;
             *      return false;
             * }
             */
        }
Beispiel #4
0
        public static int CryptoRandomInt(uint _Length = 1)
        {
            int length = (int)HEVMath.Max(1, _Length);

            return(CryptoRandomInt(0, (10 ^ length) - 1));
        }