. NET production of small restaurant and Game Equipment Program _ Practical Skills

Source: Internet
Author: User
Tags clear screen random seed

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

<%@ 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

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: weights > Public dictionary<string, I
  nt> goods = new dictionary<string, int> ();
 
  public int totalweight = 0;
      public class Good {///<summary>///name///</summary> public string name {get;
    Set
      ///<summary>///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" players, Hey hei///</s
    ummary> 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 more than a few restaurants, only 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 (equip) protected void Btnrandom_click (object sender, EventArgs e) {initgoods ();
 
    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 + "Item Name:" + kvp. Key + "  Weight:" + kvp.
    Value + "  Number of bursts:" + 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 + "  Number of bursts:" + c.tostring () + "  burst out rate:" + rate + "%<br/>";
  }///<summary>///the range///</summary>///<param name= "Weight" based on random weights ></param>
    protected void Produceresult (int Weight) {int min = 1;
    int max = 1; foreach (keyvaluepair<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> priv
    ate static 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.