/// <summary> /// 随机生成 /// </summary> /// <param name="RedCount">最小值</param> /// <param name="BlueCount">最大值</param> /// <param name="LotteryName">个数</param> /// <returns></returns> private List<int> getRandomNum(int MinNumber,int MaxNumber,int Count) { List<int> result = new List<int>(Count); Random random = new Random(); int temp = 0; while (result.Count < Count) { temp = random.Next(MinNumber, MaxNumber+1); if (MaxNumber > 9)//3d除外 { if (!result.Contains(temp))//去重 { result.Add(temp); } } else { result.Add(temp); } } return result; } /// <summary> /// 随机双色球投注号 /// </summary> /// <param name="RedCount">红球个数</param> /// <param name="BlueCount">篮球个数</param> /// <returns>投注号</returns> private string getSSQBetNumber(int RedCount,int BlueCount) { List<int> RedList = getRandomNum(1, 33, RedCount); RedList.Sort(); StringBuilder sbR = new StringBuilder(); foreach (var item in RedList) { if (item < 10) sbR.Append("0" + item.ToString()); else sbR.Append(item.ToString()); sbR.Append(BetDivision); } StringBuilder sbB = new StringBuilder(); List<int> BlueList = getRandomNum(1, 15, BlueCount); foreach (var item in BlueList) { if (item < 10) sbB.Append("0" + item.ToString()); else sbB.Append(item.ToString()); sbB.Append(BetDivision); } return sbR.ToString().Substring(0, sbR.ToString().Length - 1) + BetJoint + sbB.ToString().Substring(0, sbB.ToString().Length - 1); }
灵感来于http://zhoufoxcn.blog.51cto.com/792419/380423/