Public Sub Main()
创新互联是专业的汉台网站建设公司,汉台接单;提供网站设计制作、网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行汉台网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
Dim allLeft As New List(Of Integer)()
For i As Integer = 0 To 99
allLeft.Add(i + 1)
Next
Dim r As New Random()
Dim [next] As Integer
Dim level As String
For i As Integer = 0 To 5
[next] = r.[Next]() Mod allLeft.Count
If i 3 Then
level = "Third"
ElseIf i 5 Then
level = "Second"
Else
level = "First"
End If
Console.WriteLine(level " level prize is: " allLeft([next]).ToString())
allLeft.RemoveAt([next])
Next
End Sub
把你的代码发出来。
你这种方式的程序只能弄一等奖吧,为什么会有二等奖三等奖?
获奖次数跟电话号码什么关系,为什么不能重复?同一个号码不能多次获奖?那就不是重复的问题,你的提问有些不清不楚。
暂定的解决方案——
把随机生成的电话号码,赋值给公共数组,如果公共数组中存在新生成的电话号码,那么重新生成电话号码,如果电话号码不在数组中存在,那么将电话号码加入到数组中。重复以上过程,直至喊停。
我用多线程写的,你可以参考下。
系统界面图如下:(注:重置功能为清除已经中奖号码,回归1-100都可以中奖状态。)
代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Threading.Thread g_Thread = null;
Listint g_list = new Listint();
int g_Num = 0;
delegate void g_delegate();
/// summary
/// 开始
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void button2_Click(object sender, EventArgs e)
{
if(g_list.Count==100)
{
MessageBox.Show("所有数字已使用,请重置!");
return;
}
button3.Enabled = true;
Random r = new Random();
g_delegate dele= ChangeTxt;
g_Thread = new System.Threading.Thread(() =
{
while(this.IsDisposed==false)
{
g_Num = r.Next(1, 100);
if(g_list.Contains(g_Num))
{
g_Num = 1;
}
while(g_list.Contains(g_Num))
{
g_Num++;
}
this.Invoke(dele);
System.Threading.Thread.Sleep(50);
}
});
g_Thread.Start();
}
void ChangeTxt()
{
label2.Text = g_Num.ToString();
}
/// summary
/// 停止
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void button3_Click(object sender, EventArgs e)
{
//if(g_Thread.ThreadState==System.Threading.ThreadState.Running)
{
g_Thread.Abort();
g_list.Add(Convert.ToInt32(label2.Text));
}
button3.Enabled = false;
}
/// summary
/// 重置
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void button1_Click(object sender, EventArgs e)
{
g_list.Clear();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
System.Environment.Exit(0);
}
}