Public Sub Main()
創(chuàng)新互聯(lián)是專業(yè)的漢臺網(wǎng)站建設(shè)公司,漢臺接單;提供網(wǎng)站設(shè)計制作、網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行漢臺網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
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
把你的代碼發(fā)出來。
你這種方式的程序只能弄一等獎吧,為什么會有二等獎三等獎?
獲獎次數(shù)跟電話號碼什么關(guān)系,為什么不能重復(fù)?同一個號碼不能多次獲獎?那就不是重復(fù)的問題,你的提問有些不清不楚。
暫定的解決方案——
把隨機生成的電話號碼,賦值給公共數(shù)組,如果公共數(shù)組中存在新生成的電話號碼,那么重新生成電話號碼,如果電話號碼不在數(shù)組中存在,那么將電話號碼加入到數(shù)組中。重復(fù)以上過程,直至喊停。
我用多線程寫的,你可以參考下。
系統(tǒng)界面圖如下:(注:重置功能為清除已經(jīng)中獎號碼,回歸1-100都可以中獎狀態(tài)。)
代碼:
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("所有數(shù)字已使用,請重置!");
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);
}
}