国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > 綜合 > 正文

C#隨機(jī)數(shù)的應(yīng)用[原創(chuàng)]

2024-07-21 02:19:44
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
c#隨機(jī)數(shù)的應(yīng)用[原創(chuàng)]

自己動(dòng)手用c#編寫體育彩票

現(xiàn)在有很多彩票軟件神乎其神,但歸根到底都是隨機(jī)數(shù)的使用。我們用6位隨機(jī)數(shù)來(lái)演示在c#中使用隨機(jī)數(shù)
從而自己制作自己的彩票軟件:)
--------------------------------
代碼如下
/* 這是一個(gè)簡(jiǎn)單的隨機(jī)數(shù)使用
* 2004年3月29日
*/
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;

namespace mylotteryproject
{
/// <summary>
/// summary description for form1.
/// </summary>
public class mylotteryform : system.windows.forms.form
{
/// <summary>
/// required designer variable.
/// </summary>

private system.windows.forms.textbox textbox1;
private system.windows.forms.textbox textbox2;
private system.windows.forms.textbox textbox3;
private system.windows.forms.textbox textbox4;
private system.windows.forms.textbox textbox5;
private system.windows.forms.textbox textbox6;
public static int n_draw=1;
private system.windows.forms.label label1;
private system.windows.forms.label label2;
private system.windows.forms.label labeldaytime;
private system.windows.forms.label label3;
private system.windows.forms.label label4;
private system.windows.forms.label label5;
public int[] lottonumbers = new int[50]; //夠放6個(gè)隨機(jī)數(shù)字吧
public int[] result = new int[50];
private system.windows.forms.button pbsort;
private system.windows.forms.button pbend;
private system.windows.forms.button pbnextdraw;
private system.windows.forms.label labelsort;
private system.windows.forms.picturebox picturebox1;
private system.windows.forms.picturebox picturebox3;
private system.windows.forms.picturebox picturebox4;
private system.windows.forms.label label6;

private system.componentmodel.container components = null;

public mylotteryform()
{
//
// required for windows form designer support
//
initializecomponent();
//
// todo: add any constructor code after initializecomponent call
//
}

/// <summary>
/// clean up any resources being used.
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}

#region windows form designer generated code
/// <summary>
/// required method for designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>

private void initializecomponent()
{
system.resources.resourcemanager resources = new

system.resources.resourcemanager(typeof(mylotteryform));
this.textbox1 = new system.windows.forms.textbox();
this.textbox2 = new system.windows.forms.textbox();
this.textbox3 = new system.windows.forms.textbox();
this.textbox4 = new system.windows.forms.textbox();
this.textbox5 = new system.windows.forms.textbox();
this.textbox6 = new system.windows.forms.textbox();
this.pbnextdraw = new system.windows.forms.button();
this.label1 = new system.windows.forms.label();
this.label2 = new system.windows.forms.label();
this.labeldaytime = new system.windows.forms.label();
this.label3 = new system.windows.forms.label();
this.label4 = new system.windows.forms.label();
this.pbend = new system.windows.forms.button();
this.label5 = new system.windows.forms.label();
this.pbsort = new system.windows.forms.button();
this.labelsort = new system.windows.forms.label();
this.picturebox1 = new system.windows.forms.picturebox();
this.picturebox3 = new system.windows.forms.picturebox();
this.picturebox4 = new system.windows.forms.picturebox();
this.label6 = new system.windows.forms.label();
this.suspendlayout();
//
// textbox1
//
this.textbox1.backcolor = system.drawing.color.magenta;
this.textbox1.location = new system.drawing.point(106, 190);
this.textbox1.name = "textbox1";
this.textbox1.readonly = true;
this.textbox1.size = new system.drawing.size(28, 21);
this.textbox1.tabindex = 0;
this.textbox1.text = "textbox1";
//
// textbox2
//
this.textbox2.backcolor = system.drawing.color.gold;
this.textbox2.location = new system.drawing.point(144, 190);
this.textbox2.name = "textbox2";
this.textbox2.readonly = true;
this.textbox2.size = new system.drawing.size(29, 21);
this.textbox2.tabindex = 1;
this.textbox2.text = "textbox2";
//
// textbox3
//
this.textbox3.backcolor = system.drawing.color.cyan;
this.textbox3.location = new system.drawing.point(182, 190);
this.textbox3.name = "textbox3";
this.textbox3.readonly = true;
this.textbox3.size = new system.drawing.size(29, 21);
this.textbox3.tabindex = 2;
this.textbox3.text = "textbox3";
//
// textbox4
//
this.textbox4.backcolor = system.drawing.color.red;
this.textbox4.location = new system.drawing.point(221, 190);
this.textbox4.name = "textbox4";
this.textbox4.readonly = true;
this.textbox4.size = new system.drawing.size(29, 21);
this.textbox4.tabindex = 3;
this.textbox4.text = "textbox4";
//
// textbox5
//
this.textbox5.backcolor = system.drawing.color.yellow;
this.textbox5.location = new system.drawing.point(259, 190);
this.textbox5.name = "textbox5";
this.textbox5.readonly = true;
this.textbox5.size = new system.drawing.size(29, 21);
this.textbox5.tabindex = 4;
this.textbox5.text = "textbox5";
//
// textbox6
//
this.textbox6.backcolor = system.drawing.color.lime;
this.textbox6.location = new system.drawing.point(298, 190);
this.textbox6.name = "textbox6";
this.textbox6.readonly = true;
this.textbox6.size = new system.drawing.size(28, 21);
this.textbox6.tabindex = 5;
this.textbox6.text = "textbox6";
//
// pbnextdraw
//
this.pbnextdraw.backcolor = system.drawing.color.palegoldenrod;
this.pbnextdraw.cursor = system.windows.forms.cursors.hand;
this.pbnextdraw.flatstyle = system.windows.forms.flatstyle.flat;
this.pbnextdraw.font = new system.drawing.font("microsoft sans serif", 12f,

system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(0)));
this.pbnextdraw.forecolor = system.drawing.color.goldenrod;
this.pbnextdraw.location = new system.drawing.point(10, 250);
this.pbnextdraw.name = "pbnextdraw";
this.pbnextdraw.size = new system.drawing.size(211, 43);
this.pbnextdraw.tabindex = 6;
this.pbnextdraw.text = "下一注 >";
this.pbnextdraw.click += new system.eventhandler(this.pbnextdraw_click);
//
// label1
//
this.label1.backcolor = system.drawing.color.coral;
this.label1.font = new system.drawing.font("comic sans ms", 18f,

system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(0)));
this.label1.location = new system.drawing.point(38, 17);
this.label1.name = "label1";
this.label1.size = new system.drawing.size(384, 43);
this.label1.tabindex = 7;
this.label1.text = "infofox.org彩票軟件 .net0.01v";
//
// label2
//
this.label2.font = new system.drawing.font("microsoft sans serif", 12f,

system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(0)));
this.label2.forecolor = system.drawing.color.indianred;
this.label2.location = new system.drawing.point(29, 129);
this.label2.name = "label2";
this.label2.size = new system.drawing.size(211, 25);
this.label2.tabindex = 8;
this.label2.text = "買6個(gè)數(shù)字肯定可以中獎(jiǎng)";
//
// labeldaytime
//
this.labeldaytime.font = new system.drawing.font("microsoft sans serif", 12f,

system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(0)));
this.labeldaytime.forecolor = system.drawing.color.fromargb(((system.byte)(192)),

((system.byte)(192)), ((system.byte)(0)));
this.labeldaytime.location = new system.drawing.point(250, 129);
this.labeldaytime.name = "labeldaytime";
this.labeldaytime.size = new system.drawing.size(192, 26);
this.labeldaytime.tabindex = 9;
this.labeldaytime.click += new system.eventhandler(this.labeldaytime_click);
//
// label3
//
this.label3.font = new system.drawing.font("microsoft sans serif", 10f,

system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(0)));
this.label3.location = new system.drawing.point(29, 86);
this.label3.name = "label3";
this.label3.size = new system.drawing.size(43, 25);
this.label3.tabindex = 10;
this.label3.text = "第";
this.label3.textalign = system.drawing.contentalignment.middleleft;
this.label3.click += new system.eventhandler(this.label3_click);
//
// label4
//
this.label4.backcolor = system.drawing.color.bisque;
this.label4.borderstyle = system.windows.forms.borderstyle.fixed3d;
this.label4.font = new system.drawing.font("microsoft sans serif", 10f,

system.drawing.fontstyle.regular, system.drawing.graphicsunit.point, ((system.byte)(0)));
this.label4.forecolor = system.drawing.color.red;
this.label4.location = new system.drawing.point(106, 86);
this.label4.name = "label4";
this.label4.size = new system.drawing.size(48, 26);
this.label4.tabindex = 11;
this.label4.textalign = system.drawing.contentalignment.middlecenter;
//
// pbend
//
this.pbend.backcolor = system.drawing.systemcolors.control;
this.pbend.cursor = system.windows.forms.cursors.hand;
this.pbend.forecolor = system.drawing.systemcolors.controltext;
this.pbend.location = new system.drawing.point(355, 258);
this.pbend.name = "pbend";
this.pbend.size = new system.drawing.size(96, 25);
this.pbend.tabindex = 12;
this.pbend.text = "退出";
this.pbend.click += new system.eventhandler(this.pbend_click);
//
// label5
//
this.label5.borderstyle = system.windows.forms.borderstyle.fixed3d;
this.label5.font = new system.drawing.font("times new roman", 14f,

system.drawing.fontstyle.regular, system.drawing.graphicsunit.point, ((system.byte)(0)));
this.label5.location = new system.drawing.point(0, 310);
this.label5.name = "label5";
this.label5.size = new system.drawing.size(470, 25);
this.label5.tabindex = 13;
this.label5.text = "您中了頭獎(jiǎng)- 別忘了我啊http://infofox.org";
//
// pbsort
//
this.pbsort.backcolor = system.drawing.systemcolors.control;
this.pbsort.forecolor = system.drawing.systemcolors.controltext;
this.pbsort.location = new system.drawing.point(240, 258);
this.pbsort.name = "pbsort";
this.pbsort.size = new system.drawing.size(96, 25);
this.pbsort.tabindex = 14;
this.pbsort.text = " 開(kāi)始計(jì)算";
this.pbsort.textalign = system.drawing.contentalignment.middleleft;
this.pbsort.click += new system.eventhandler(this.pbsort_click);
//
// labelsort
//
this.labelsort.location = new system.drawing.point(38, 190);
this.labelsort.name = "labelsort";
this.labelsort.size = new system.drawing.size(58, 24);
this.labelsort.tabindex = 15;
this.labelsort.text = "sorted:";
this.labelsort.textalign = system.drawing.contentalignment.middleleft;
//
// picturebox1
//
this.picturebox1.image = ((system.drawing.image)(resources.getobject

("picturebox1.image")));
this.picturebox1.location = new system.drawing.point(248, 72);
this.picturebox1.name = "picturebox1";
this.picturebox1.size = new system.drawing.size(40, 40);
this.picturebox1.tabindex = 16;
this.picturebox1.tabstop = false;
//
// picturebox3
//
this.picturebox3.image = ((system.drawing.image)(resources.getobject

("picturebox3.image")));
this.picturebox3.location = new system.drawing.point(312, 72);
this.picturebox3.name = "picturebox3";
this.picturebox3.size = new system.drawing.size(40, 40);
this.picturebox3.tabindex = 18;
this.picturebox3.tabstop = false;
//
// picturebox4
//
this.picturebox4.image = ((system.drawing.image)(resources.getobject

("picturebox4.image")));
this.picturebox4.location = new system.drawing.point(376, 72);
this.picturebox4.name = "picturebox4";
this.picturebox4.size = new system.drawing.size(40, 40);
this.picturebox4.tabindex = 19;
this.picturebox4.tabstop = false;
//
// label6
//
this.label6.font = new system.drawing.font("microsoft sans serif", 10f,

system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((system.byte)(0)));
this.label6.location = new system.drawing.point(168, 88);
this.label6.name = "label6";
this.label6.size = new system.drawing.size(43, 25);
this.label6.tabindex = 20;
this.label6.text = "張";
this.label6.textalign = system.drawing.contentalignment.middleleft;
//
// mylotteryform
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.backcolor = system.drawing.color.bisque;
this.clientsize = new system.drawing.size(458, 339);
this.controls.add(this.label6);
this.controls.add(this.picturebox4);
this.controls.add(this.picturebox3);
this.controls.add(this.picturebox1);
this.controls.add(this.labelsort);
this.controls.add(this.pbsort);
this.controls.add(this.label5);
this.controls.add(this.pbend);
this.controls.add(this.label4);
this.controls.add(this.label3);
this.controls.add(this.labeldaytime);
this.controls.add(this.label2);
this.controls.add(this.label1);
this.controls.add(this.pbnextdraw);
this.controls.add(this.textbox6);
this.controls.add(this.textbox5);
this.controls.add(this.textbox4);
this.controls.add(this.textbox3);
this.controls.add(this.textbox2);
this.controls.add(this.textbox1);
this.forecolor = system.drawing.color.indianred;
this.formborderstyle = system.windows.forms.formborderstyle.fixed3d;
this.maximizebox = false;
this.name = "mylotteryform";
this.startposition = system.windows.forms.formstartposition.centerscreen;
this.text = ".net彩票狐貍";
this.load += new system.eventhandler(this.mylotteryform_load);
this.resumelayout(false);

}
#endregion

/// <summary>
/// the main entry point for the application.
/// </summary>
[stathread]
static void main()
{
application.run(new mylotteryform());
}

private void mylotteryform_load(object sender, system.eventargs e)
{

//開(kāi)始
int c=1000;
int[] numb = new int[c];
datetime dt = new datetime();
dt = datetime.now;
random rnd = new random(dt.millisecond);
for (int i=0; i<c; i++)
{
numb[ i ] = rnd.next(1,45);
}
array.sort(numb);
int k=0;
int j=0;
for (int i=0; i<c-1; i++)
{
if (numb[ i ] == numb[i+1])
{
result[k] = numb[ i ];
lottonumbers[k] = j+=1;
}
else
{
k+=1;
j=0;
}
}

array.sort(lottonumbers, result);
fndisplay6numbers(); // 第一個(gè)顯示的數(shù)字

array.sort(result);

datetime dt1= datetime.today; //取今天的日期啊,上帝保佑我中獎(jiǎng)吧


this.labeldaytime.text=dt1.tolongdatestring(); //顯示日期
this.label4.text=n_draw.tostring(); //顯示數(shù)字
this.labelsort.visible=false;
this.pbnextdraw.focus();

//--------------結(jié)束
}

private void fndisplay6numbers()
{
// 在框里顯示數(shù)字
this.textbox1.text = result[49].tostring();
this.textbox2.text = result[48].tostring();
this.textbox3.text = result[47].tostring();
this.textbox4.text = result[46].tostring();
this.textbox5.text = result[45].tostring();
this.textbox6.text = result[44].tostring();
}

private void fndisplay6numberssorted()
{
int[] nr = new int[6];
nr[0]=convert.toint16(this.textbox1.text);
nr[1]=convert.toint16(this.textbox2.text);
nr[2]=convert.toint16(this.textbox3.text);
nr[3]=convert.toint16(this.textbox4.text);
nr[4]=convert.toint16(this.textbox5.text);
nr[5]=convert.toint16(this.textbox6.text);

array.sort(nr);
this.textbox1.text = nr[0].tostring();
this.textbox2.text = nr[1].tostring();
this.textbox3.text = nr[2].tostring();
this.textbox4.text = nr[3].tostring();
this.textbox5.text = nr[4].tostring();
this.textbox6.text = nr[5].tostring();
}

private void pbnextdraw_click(object sender, system.eventargs e)
{
this.mylotteryform_load(sender, e);
n_draw++;
this.label4.text=n_draw.tostring(); //在框里隨便顯示數(shù)字
//按“下注”的按鈕后
this.pbsort.enabled=true;
}

private void pbend_click(object sender, system.eventargs e)
{
application.exit();
}

private void pbsort_click(object sender, system.eventargs e)
{
fndisplay6numberssorted(); //調(diào)用
this.pbsort.enabled=false;
this.labelsort.visible=true;
this.pbnextdraw.focus();
}

private void labeldaytime_click(object sender, system.eventargs e)
{

}

private void label3_click(object sender, system.eventargs e)
{

}

}
}


最大的網(wǎng)站源碼資源下載站,

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 城步| 荆州市| 浦东新区| 万全县| 阳泉市| 饶阳县| 淮滨县| 华蓥市| 桂平市| 南江县| 那坡县| 苏尼特左旗| 吐鲁番市| 莫力| 株洲市| 岱山县| 科技| 甘南县| 曲周县| 葫芦岛市| 鹤山市| 德昌县| 英德市| 全州县| 黄石市| 绥化市| 阿荣旗| 昌平区| 永善县| 兴化市| 灯塔市| 林周县| 宁波市| 洱源县| 清新县| 公安县| 应城市| 黑山县| 台江县| 鹿邑县| 肇东市|