This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19995|Reply: 1

[Source] C# generates random numbers

[Copy link]
Posted on 10/30/2015 2:50:33 PM | | |
  1. /// <summary>
  2.         /// 创建随机数
  3.         /// </summary>
  4.         /// <param name="num"></param>
  5.         /// <returns></returns>
  6.         private string CreateRandom(int num)
  7.         {
  8.             string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  9.             StringBuilder sb = new StringBuilder();
  10.             for (int i = 0; i < num; i++)
  11.             {
  12.                 sb.Append(str[new Random(Guid.NewGuid().GetHashCode()).Next(0, str.Length - 1)]);
  13.             }
  14.             return sb.ToString();
  15.         }
Copy code






Previous:EasyUI datagrid empty data
Next:Bootstrap Datatable is a simple basic configuration
 Landlord| Posted on 11/12/2015 10:45:43 AM |
  1. /// <summary>
  2.         /// 生成指定长度的随机码。
  3.         /// </summary>
  4.         private string CreateRandomCode(int length)
  5.         {
  6.             string[] codes = new string[36] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "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" };
  7.             StringBuilder randomCode = new StringBuilder();
  8.             Random rand = new Random();
  9.             for (int i = 0; i < length; i++)
  10.             {
  11.                 randomCode.Append(codes[rand.Next(codes.Length)]);
  12.             }
  13.             return randomCode.ToString();
  14.         }
Copy code


Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com