首页 > 代码库 > C# 生成随机数

C# 生成随机数

/// <summary>
        /// 创建随机数
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        private string CreateRandom(int num)
        {
            string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < num; i++)
            {
                sb.Append(str[new Random(Guid.NewGuid().GetHashCode()).Next(0, str.Length - 1)]);
            }
            return sb.ToString();
}

 

C# 生成随机数