Files
number_zj/20220330_Vote/Ewide.Core/Util/RandomHelper.cs
2022-03-30 19:34:37 +08:00

29 lines
812 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ewide.Core.Util
{
public class RandomHelper
{
private const string BASECODE = "ABCDEFGHJKLMNPQRSTUVWXYZ0123456789";
/// <summary>
///生成指定位数的随机码(数字)
/// </summary>
/// <param name="length"></param>
/// <returns></returns>
public static string GenerateRandomCode(int length)
{
var result = new StringBuilder();
for (var i = 0; i < length; i++)
{
var r = new Random(Guid.NewGuid().GetHashCode());
result.Append(BASECODE[r.Next(BASECODE.Length)]);
}
return result.ToString();
}
}
}