zoukankan      html  css  js  c++  java
  • 高并发下获取随机字符串

    #region 获取随机字符串

    //digit 最终返回的字符串的长度
    public static string BuildCode(int digit)
    {
    StringBuilder resultCode = new StringBuilder();
    Random ran = new Random(GetRandomSeed());
    for (int i = 0; i < digit; i++)
    {
    resultCode.Append(("0123456789").Substring(ran.Next(0, 10), 1));
    }

    string resultCode1 = resultCode.ToString();
    return resultCode1;
    }

    static int GetRandomSeed()
    {
    byte[] bytes = new byte[4];
    System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
    rng.GetBytes(bytes);
    return BitConverter.ToInt32(bytes, 0);
    }
    #endregion

  • 相关阅读:
    win_tc使用感受
    10进制转8进制(栈操作)
    动态栈
    数组
    单链表学习
    static用法
    基础2
    linux c first
    linux net command /uboot command
    opencv
  • 原文地址:https://www.cnblogs.com/zxk3113/p/5231947.html
Copyright © 2011-2022 走看看