1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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
- {
- /// <summary>
- /// 秒表开始
- /// </summary>
- /// <returns></returns>
- public static Stopwatch SwStart()
- {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- return sw;
- }
- /// <summary>
- /// 秒表停止返回时间
- /// </summary>
- /// <param name="sw"></param>
- /// <returns></returns>
- public static double SwStop(this Stopwatch sw)
- {
- sw.Stop();
- return sw.ElapsedMilliseconds;
- }
- public delegate void DelegateSw();
- /// <summary>
- /// 无参方法执行
- /// </summary>
- /// <param name="delegateSw"></param>
- /// <returns></returns>
- public static double Sw(DelegateSw delegateSw)
- {
- var sw = SwStart();
- delegateSw();
- return sw.SwStop();
- }
- /// <summary>
- /// 根据array生x个随机数
- /// </summary>
- /// <param name="x">生成几个随机数</param>
- /// <param name="array">数组 起始数字、结束数字</param>
- /// <returns></returns>
- public static IEnumerable<int> RandomInt(int x, int[] array,List<int> 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;
- }
- }
- }
- }
|