class Program
{
static void Main(string[] args)
{
RandNum a = new RandNum();
a.UI();
Console.Read();
}
}
public class RandNum
{
public List<int> ExNum { get; set; }//已经抽中的数
public List<int> TotalNum { get; set; }
private int count; //范围
private int SELCOUNT;
private int selCount;//选几个
/// <summary>
///
/// </summary>
/// <param name="ct">大于零的整数</param>
public RandNum()
{
ExNum = new List<int>();
TotalNum = new List<int>();
}
private void Run()
{
Random r = new Random();
do
{
int num = 0;
int i = r.Next(TotalNum.Count);
num = TotalNum[i];
ExNum.Add(num);
TotalNum.RemoveAt(i);
System.Threading.Thread.Sleep(10000);//10秒中抽一个出来
Console.WriteLine("\r第{0}个易做图号码已产生:{1}", SELCOUNT - GetCurrentCount()+1, num);
} while (Interlocked.Decrement(ref selCount) > 0);
}
public void UI()
{
while (true)
{
Console.WriteLine("===========YY抽奖程序===========");
Console.WriteLine("请输入要抽奖的总数(从0开始编号)");
string s = Console.ReadLine();
int ct = Convert.ToInt32(s);
if (ct <= 0)
Console.WriteLine("输入大于零的整数");
else
{
Console.WriteLine("请输入要从中选从少个数");
string s1 = Console.ReadLine();
int ct1 = Convert.ToInt32(s1);
if (ct1 <= 0)
Console.WriteLine("输入大于零的整数");
//开始计算
Console.WriteLine("开始抽奖...");
Task.Factory.StartNew(Run);
Random r = new Random();
while (true)
{
Console.Write(r.Next(count));
System.Threading.Thread.Sleep(500);
Console.Write("\r");
Console.Write(" \r");
if (GetCurrentCount() <= 0)
{
Console.WriteLine("抽奖结束");
Console.WriteLine("中奖序列为:");
ExNum.ForEach(Console.WriteLine);