using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IoTIntegrationPlatform.Common
{
///
/// 随机数
///
public static class RandomHelper
{
///
/// 生成指定长度的随机数
///
///
///
public static string GenerateRandomStr(int length)
{
StringBuilder sb = new StringBuilder();
try
{
//const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const string chars = "ABCDEF0123456789";
Random rand = new Random();
for (int i = 0; i < length; i++) // 生成指定长度的随机字符串
{
sb.Append(chars[rand.Next(chars.Length)]);
}
}
catch (Exception ex)
{
Logging.Error(ex, ex.Message);
}
return sb.ToString();
}
}
}