求 C# 抽奖程序,该怎么解决
求 C# 抽奖程序
我想实现的功能如下:
有1到5000 这5000个数字
我第一次随机抽出30个不同的数字
第二次随机抽出10个不同的数字(不能含有第一次抽中的数字)
第二次随机抽出5个不同的数字(不能含有前两次抽中的数字)
哪位大哥有这样的程序,能否发我一份
邮箱: sun77@163.com
谢谢
------解决方案--------------------
我想实现的功能如下:
有1到5000 这5000个数字
我第一次随机抽出30个不同的数字
第二次随机抽出10个不同的数字(不能含有第一次抽中的数字)
第二次随机抽出5个不同的数字(不能含有前两次抽中的数字)
哪位大哥有这样的程序,能否发我一份
邮箱: sun77@163.com
谢谢
------解决方案--------------------
- C# code
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { List<List<int>> TValues = new List<List<int>>(); List<int> TFirst = GetValue(30, null);//获得30个随机数泛型集合 TValues.Add(TFirst); List<int> TSecond = GetValue(10, TValues);//获得10个随机数泛型集合 TValues.Add(TSecond); List<int> TThird = GetValue(5, TValues);//获得5个随机数泛型集合 Console.WriteLine("30个数:" + GetString(TFirst)); Console.WriteLine("10个数:" + GetString(TSecond)); Console.WriteLine("5个数:" + GetString(TThird)); } private static List<int> GetValue(int count, List<List<int>> TValues) { List<int> TValue = new List<int>(); Random random = new Random(); int i = 0; int value = 0; while (i < count) { bool bExist = false; value = random.Next(1, 5001); if (TValues != null) { foreach (List<int> Ttmp in TValues) { if (Ttmp.Contains(value)) { bExist = true; break; } } } if (!bExist) { if (!TValue.Contains(value)) { TValue.Add(value); i++; } } } return TValue; } private static string GetString(List<int> T) { string back = ""; foreach (int value in T) { if (back == "") back = value.ToString(); else back += "," + value.ToString(); } return back; } } }
------解决方案--------------------
public int getNum(int[] arrNum,int tmp,int minValue,int maxValue,Random ra){
int n=0;
while (n<=arrNum.Length-1)
{
if (arrNum[n]==tmp)
{
tmp=ra.Next(minValue,maxValue);
getNum(arrNum,tmp,minValue,maxValue,ra);
}
n++;
}
return tmp;
}
参考
------解决方案--------------------
- C# code
using System; class a { public struct infomation { public const string name = "mark"; public const string contry = "china"; } } class b { static void Main() { a aa = new a(); Console.WriteLine("name:{0} contry:{1}",a.infomation.name,a.infomation.contry); Console.ReadLine(); } }