This article mainly Introduces ASP that easily achieves red packet snatching. NET code, has a certain reference value, interested friends can refer to this article for everyone to introduce easily achieve the ASP of red packet snatching. NET code, has a certain reference value, interested friends can refer
The group is playing with snatching red packets, snatching and sending them again, which is boring. programmers are interested in how to implement it. here we will briefly talk about the implementation ideas, attach dome, and the code is a bit low, fortunately, it is implemented. the specific content is as follows:
Body
100 yuan and 30 red packets
4. disrupt the order. careful garden friends may find that red packets are ordered. we must simply write a function to disrupt it.
Demo
////// Grab a red envelope ////////////
Public List
Qhb (int money, int num) {int min = 1; int pjs = money/num; List
List = new List
(); Random rnd = new Random (); for (int I = 0; I <num; I ++) {int max = (money/(num-I )) * 2; int s = rnd. next (min, max); s = checkmoney (s, min, max); list. add (s); money-= s;} // the previous data is reasonable, and the end must be more than or equal to list = checklist (money, pjs, list); return list ;}
////// Remainder processing ////////////
Public List
Checklist (int money, int pjs, List
List) {if (money! = 0) {if (money> 0) {List
List_order = maopao (list); // minimum if (money/pjs = 0) {list_order [0] + = money;} else {for (int I = 0; I <money/pjs + 1; I ++) {if (I = money/pjs) {list_order [I] + = (money-(money/pjs) * pjs);} else {list_order [I] + = pjs ;}}return list_order;} else {List
List_order = maopao (list, "desc"); // returns the maximum if (money/pjs = 0) {list_order [0] + = money ;} else {for (int I = 0; I <-(money/pjs) + 1; I ++) {if (I =-(money/pjs )) {list_order [I] + = (money-(money/pjs) * pjs);} else {list_order [I]-= pjs ;}} return list_order ;}} return list ;}
////// Bubble sort ////////////
Public List
Maopao (List
List, string order = "asc") {if (order! = "Asc") {for (int I = 0; I <list. count; I ++) {for (int j = 0; j <list. count-I-1; j ++) {if (list [j + 1]> list [j]) {int temp = list [j]; list [j] = list [j + 1]; list [j + 1] = temp ;}}} else {for (int I = 0; I <list. count; I ++) {for (int j = 0; j <list. count-i-1; j ++) {if (list [j + 1] <list [j]) {int temp = list [j]; list [j] = list [j + 1]; list [j + 1] = temp ;}}} return list ;}
////// Disrupt the order /////////
Public List
Suiji (List
List) {Random rnd = new Random (); for (int I = 0; I <list. count; I ++) {int temp = list [I]; int j = rnd. next (0, list. count-1); list [I] = list [j]; list [j] = temp;} return list ;}
The above is the detailed content of the ASP. NET code that easily achieves red packet snatching. For more information, see other articles on php Chinese network!