Yi.Framework.Net6/Yi.Framework.Common/Helper/RandomHelper.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Yi.Framework.Common.Helper
{
    public class RandomHelper
    {
        public static string replaceBianLiang(string content)
        {
            content = content.Replace("{当前时间}", DateTime.Now.TimeOfDay.ToString());
            string[] bianliang = new string[] { "{随机字母}", "{随机数字}", "{随机汉字}" };
            Regex r;
            int count;
            string readstr = "";
            foreach (string str in bianliang)
            {
                count = (content.Length - content.Replace(str, "").Length) / str.Length;
                if (str == "{随机汉字}") readstr = RandChina(count);
                if (str == "{随机数字}") readstr = GenerateCheckCodeNum(count);
                if (str == "{随机字母}") readstr = GenerateRandomLetter(count);
                if (count > readstr.Length) count = readstr.Length;
                r = new Regex(str.Replace("{", "\\{").Replace("}", "\\}"));
                for (int i = 0; i < count; i++)
                {
                    content = r.Replace(content, readstr.Substring(i, 1), 1);
                }
            }
            return content;
        }


        /// <summary>
        /// 随机生成字母
        /// </summary>
        /// <param name="Length"></param>
        /// <returns></returns>
        public static string GenerateRandomLetter(int Length)
        {
            char[] Pattern = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
            string result = "";
            int n = Pattern.Length;
            Random random = new Random(~unchecked((int)DateTime.Now.Ticks));
            for (int i = 0; i < Length; i++)
            {
                int rnd = random.Next(0, n);
                result += Pattern[rnd];
            }
            return result;
        }

        /// <summary>
        /// 随机生成数字
        /// </summary>
        /// <param name="codeCount"></param>
        /// <returns></returns>
        public static string GenerateCheckCodeNum(int codeCount)
        {
            int rep = 0;
后面还有 39 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。