using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common
{
public static class OtherHelper
{
///
/// 秒表开始
///
///
public static Stopwatch SwStart()
{
Stopwatch sw = new Stopwatch();
sw.Start();
return sw;
}
///
/// 秒表停止返回时间
///
///
///
public static double SwStop(this Stopwatch sw)
{
sw.Stop();
return sw.ElapsedMilliseconds;
}
public delegate void DelegateSw();
///
/// 无参方法执行
///
///
///
public static double Sw(DelegateSw delegateSw)
{
var sw = SwStart();
delegateSw();
return sw.SwStop();
}
///
/// 根据array生x个随机数
///
/// 生成几个随机数
/// 数组 起始数字、结束数字
///
public static IEnumerable RandomInt(int x, int[] array,List list)
{
if (array.Length != 2)
yield break;
for (int i = 0; i < x; i++)
{
var ra = new Random(Guid.NewGuid().GetHashCode());
var content = ra.Next(array[0], array[1] + 1);
while (list.Contains(content))
{
content = ra.Next(array[0], array[1] + 1);
}
yield return content;
}
}
}
}