using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplicationTest
{
class Program
{
static void Main(string[] args)
{
Random random = new Random();
for (int i = 0; i < 5; i++)
{
Console.WriteLine(getLastNum(random));
}
Console.ReadKey();
}
static string getFirstNum(Random random)
{
string results = "";
int[] range = new int[33];
for (int i = 0; i < 33; i++)//初始化范围集合,从1到33
{
range[i] = i + 1;
}
int[] result = CreateNumbers(random, range, 6);
ArrayList al = new ArrayList();
for (int i = 0; i < result.Length; i++)
{
al.Add(result[i]);
}
al.Sort();
for (int i = 0; i < result.Length; i++)
{
if (Convert.ToInt32(al[i]) < 10)
{
al[i] = "0" + al[i].ToString();
}
}
results = al[0].ToString() + "," + al[1].ToString() + "," + al[2].ToString() + "," + al[3].ToString() + "," + al[4].ToString() + "," + al[5].ToString();
return results;
}
static string getLastNum(Random random)
{
int num = random.Next(1, 12);
string results = getFirstNum(random) + "+" + (num < 10 ? "0" + num.ToString() : num.ToString());
return results;
}
//取出不重复的6个数
static int[] CreateNumbers(Random random, int[] range, int count)
{
int[] result = new int[count];
int index = 0;
int temp = 0;
for (int i = 0; i < count; i++)
{
index = random.Next() % (range.Length - i);
result[i] = range[index];
//将当前已使用过的数移至集合末尾,并且将末尾原来没有使用的数放到当前位置
temp = range[range.Length - 1 - i];
range[range.Length - 1 - i] = range[index];
range[index] = temp;
}
return result;
}
}
}