發布時間:2020-08-07 05:03 作者:獨孤劍 閱讀:1268
using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { Console.WriteLine(GenerateNonceNum(5)); Console.Read(); } /// <summary> /// 生成隨機數字 /// </summary> /// <param name="length">字符串長度</param> /// <returns></returns> public static string GenerateNonceNum(int length) { char[] chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', }; string result = ""; Random rnd = new Random(Guid.NewGuid().GetHashCode()); for (int i = 0; i < length; i++) { result += chars[rnd.Next(chars.Length)]; } return result; } } }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞