Demo Set 8 awards, each award can be customized to the winning rate, the accuracy of 1/10000
Public stringPrizedraw () {//prizes and winning rates Const stringPrizestring ="Prize One: 33, Prize II: 30, Prize Three: 9, Prize Four: 8, Prize Five: 7, Prize Six: 6, Prize Seven: 5, Prize eight: 2"; //the winning rate is *100, placed in the array, and sorted from small to large varPrizearray = Prizestring.split (','). Select (j =New{Prize = J.split (':')[0], change = (int)(Double. Parse (J.split (':')[1])* -) }). (j =j.change). ToArray (); //accumulate the winning rate and put it in the dictionary varPrizedictionary =Newdictionary<string,int>(); for(vari =0; I <8; i++) { varAllchange =0; for(varj =0; J <= I; J + +) {Allchange+=Prizearray[j]. change; } prizedictionary.add (Prizearray[i]. Prize, Allchange); } //generate a random number of 1-10000 varRD =NewRandom (); varRdchange = Rd. Next (1,10001); //find the first prize that is greater than a random value returnPrizedictionary.first (j = J.value >=rdchange). Key; }
. NET C # Sweepstakes, winning