. NET production of restaurants and game equipment Small program

Source: Internet
Author: User
Tags foreach clear screen min random seed

This article mainly introduced. NET production of the small restaurant and game equipment, small partners in the future no longer need to consider where to eat every day, very fun and practical, need friends can refer to the

-->

Just create a new ASP.net Web project and drag it in. Now know why the game is always not good equipment, because his weight is very small ... Eat at noon at random, want to go to which one, the weight value set a little bit, and then, the fate of it!

Default.aspx

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>   <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

Default.aspx.cs

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148-149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179-18 0 181 182 183 184 185 186 187 188 189 190 191-192 Using System; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.Web.UI; Using System.Web.UI.WebControls;   public partial class _default:system.web.ui.page {//<string,int>:< name: weight > Public dictionary< string, int> goods = new dictionary<string, int> (); public int totalweight = 0;   public class Good {///<summary>///names///</summary> public string name {get; set;}///<summar y>///weights (greater than or equal to 1, otherwise the probability is 0)///</summary> public int Weight {get; set;}}   Public list<good> result = new list<good> ();   protected void Page_Load (object sender, EventArgs e) {}  ///<summary>///Initialization Equipment I am the "dream three" player, hehe///< /summary> protected void Initgoods () {goods.clear (); totalweight = 0;   Goods.add ("Ice Claw", 2); Artifact (fist claw type) goods.add ("Heavy Fur", 300); Goods.add ("Small Fur", 1000); Goods.add ("Light Fur", 1000); Goods.add ("The creation of the God's Defense", 5); Goods.add ("Legend of Weapons to create a book", 20); Goods.add ("Rosewood Branch", 300); GoOds. ADD ("Hard Fur", 600); Goods.add ("Erotic crystal", 8); Goods.add ("True dragon-Roasted sword", 30); Goods.add ("Dong Zhuo Soul", 1); Artifact (long handle Class)   foreach (keyvaluepair<string, int> kvp in goods) {totalweight = kvp. Value; }  ///<summary>///Initialization Restaurant, the company downstairs restaurant more, only write a few, meaning ... </summary> protected void Initfood () {goods.clear (); totalweight = 0;   Goods.add ("Halal Lanzhou", 1); Goods.add ("Changan Guest", 1); Goods.add ("Welcome pine", 1); Goods.add ("Auspicious chaos", 1);   foreach (keyvaluepair<string, int> kvp in goods) {totalweight = kvp. Value; }   protected int gettryparse () {try {return int. Parse (Txtnum.text); catch {return 1;}}  //start draw (equipment) protected void Btnrandom_click (object sender, EventArgs e) {initgoods ();   Lblresult.text = Lblres Ult. Text + "<br/>";   int Count = Gettryparse (); for (int i = 1; I <= Count; i++) {Random RDM = new Random (Getrandomseed ());   int Weight = RDM. Next (1, totalweight + 1);   Produceresult (Weight); }   foreach (keyvaluepair<sTring, int> kvp in goods) {int c = result.count (d => d.name = = kvp. Key); Double rate = c * 1.0/count * 1.0 * 100;   Lblresult.text = lblresult.text + "Item Name:" + kvp. Key + "Weight:" + kvp. Value + "burst out the number of times:" + c.tostring () + "burst out rate:" + rate + "%<br/>"; }    //start Draw (restaurant) protected void Btnrandomfood_click (object sender, EventArgs e) {initfood ();   Lblresult . Text = Lblresult.text + "<br/>";   int Count = Gettryparse (); for (int i = 1; I <= Count; i++) {Random RDM = new Random (Getrandomseed ());   int Weight = RDM. Next (1, totalweight + 1);   Produceresult (Weight); }   foreach (keyvaluepair<string, int> kvp in goods) {int c = result.count (d => d.name = = kvp. Key); Double rate = c * 1.0/count * 1.0 * 100;   Lblresult.text = Lblresult.text + "Restaurant name:" + kvp. Key + "Weight:" + kvp. Value + "burst out the number of times:" + c.tostring () + "burst out rate:" + rate + "%<br/>"; { }  ///<summary>///based on random weights///</summary>///&Lt;param name= "Weight" ></param> protected void Produceresult (int Weight) {int min = 1; int max = 1; foreach (Key Valuepair<string, int> kvp in goods) {max = min + kvp. Value-1;   if (Weight >= min && Weight <= max) {Good g = new Good (); g.name = kvp. Key; G.weight = kvp. Value; Result.add (g); Return }   min = max + 1; }  ///<summary>///random seed value (prevent repetition caused by too fast)///</summary>///<returns></returns> Private STA TIC int getrandomseed () {byte[] bytes = new Byte[4]; System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider (); Rng. GetBytes (bytes); Return Bitconverter.toint32 (bytes, 0);  //Clear screen operation protected void Btnclear_click (object sender, EventArgs e) {lblresult.text = "";}}

The above mentioned is the entire content of this article, I hope you can enjoy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.