using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace LXYD.WebGame.Common.Misc
{
public class CommonHelper
{
public static int GetRandom(int min, int max)
{
Random random = new Random(GetRandomSeedbyGuid());
int value = random.Next(min, max);
return value;
}
/// <summary>
/// 使用Guid生成种子
/// </summary>
/// <returns></returns>
private static int GetRandomSeedbyGuid()
{
Thread.Sleep(100);//为防止时间过短的生成, 导致重复问题, 休眠100毫秒
return Guid.NewGuid().GetHashCode();
}
/// <summary>
/// 随机获取List里的某个值
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
public static int RandomGetListValue(List<int> array)
{
int count = array.Count;
Random random = new Random(GetRandomSeedbyGuid());
var index = random.Next(0, count);
return array[index];
}
}
}