• Asp.net生成随机不重复的函数(方法)


    // 生成三位毫秒字串 
            public static string Get_mSec() 
            { 
                string mSec = System.DateTime.Now.Millisecond.ToString(); 
                mSec = "00" + mSec; 
                return mSec.Substring(mSec.Length - 3, 3); 
            } 

    // 生成 xLen 位随机字串 xRandom 为不同序号(作为种子数) 
            public static string Rnd_ID4(int xLen, int xRandom) 
            { 
                string oStr = ""; 
                int nSeed = int.Parse(System.DateTime.Now.Ticks.ToString().Substring(8, 8)); 
                double dSeed = Math.Sqrt(xRandom + 123.456) + Math.Sqrt(nSeed); 
                nSeed = (int)(2345678 * Math.Sqrt(dSeed)); 
                System.Random ran = new System.Random(nSeed); 
                for (int i = 0; i < System.Math.Abs(xLen); i++) 
                { 
                    int rin = ran.Next(0, 33 - 1); 
                    oStr += ("0123456789ABCDEFGHJKLMNPQRSTUVWXY").Substring(rin, 1); 
                } 
                return oStr; 
            } 

    // 使用方法: 

            Response.Write(" <br>- "); 
            string StrA = "(Peace)乱码人生<br>"; 
            string StrB = ""; 


            for (i = 0; i < 320; i++) 
            { 

                StrB = Get_mSec() + "-" + Rnd_ID4(8, i); 
                if (StrA.IndexOf(StrB) >= 0) 
                { 
                    Response.Write("<br>i=" + i.ToString() + " : (重复) - " + "- " + StrB); 
                } 
                else 
                { 
                    StrA += StrB + "<BR>"; 
                } 

            } 

            Response.Write(" <br><br><br> "); 
            Response.Write(StrA); 
            Response.Write(" <br><br><br> "); 

  • 相关阅读:
    应用安全-Web安全-越权漏洞整理
    操作系统
    接码平台 | 临时邮箱生成网站
    shell反弹/端口转发/端口映射/内网穿透/代理/SSH中转/TLS加密传输/协议转换/DNS防污染/抓包工具整理
    远控CVE整理
    Windows系统CVE整理
    https的了解
    软件设计师备考
    https资料
    基本感觉比较好的书
  • 原文地址:https://www.cnblogs.com/xieon1986/p/3447096.html
Copyright © 2020-2023  润新知