This article mainly introduces to Xiangxu the ASP.NET code that can easily realize red envelope grabbing on WeChat. It has a certain reference value. Interested friends can refer to it.
Everyone in the group is playing Grabbing red envelopes, sending them out again, grabbing them again after sending them out, is simply boring. Programmers are interested in how to implement it. Here I briefly talk about the implementation ideas, and attach the dome. The code is a bit low, but fortunately it is implemented. The specific content is as follows
Text
##100 yuan and 30 red envelopes
50 yuan and 13 red envelopes
10 red envelopes per block
The following conditions need to be met for sending red envelopes1. The total amount remains unchanged2. Each red envelope must have money
3. Try to make it evenly distributed, otherwise it will be meaningless to grab the red envelopes
Implementation ideas1. First, determine the minimum unit, here it is accurate to the minute. I use int type for calculation here, and the results are all int type
2. The data is even, here 1
4. Disrupt the order. Careful gardeners may find that red envelopes are in order. We must simply write a function to disrupt it.
demo
/// <summary> /// 抢红包 /// </summary> /// <param> /// <param> /// <returns></returns> public List<int> qhb(int money, int num) { int min = 1; int pjs = money / num; List<int> list = new List<int>(); Random rnd = new Random(); for (int i = 0; i <pre class="brush:php;toolbar:false">/// <summary> /// 余数处理 /// </summary> /// <param> /// <param> /// <returns></returns> public List<int> checklist(int money, int pjs, List<int> list) { if (money != 0) { if (money > 0) { List<int> list_order = maopao(list); //给最小 if (money / pjs == 0) { list_order[0] += money; } else { for (int i = 0; i list_order = maopao(list,"desc"); //给最大 if (money / pjs == 0) { list_order[0] += money; } else { for (int i = 0; i <pre class="brush:php;toolbar:false"> /// <summary> /// 冒泡排序 /// </summary> /// <param> /// <param> /// <returns></returns> public List<int> maopao(List<int> list,string order = "asc") { if (order != "asc") { for (int i = 0; i list[j]) { int temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; } } } } else { for (int i = 0; i <pre class="brush:php;toolbar:false">/// <summary> /// 打乱顺序 /// </summary> /// <param> /// <returns></returns> public List<int> suiji(List<int> list) { Random rnd = new Random(); for (int i = 0; i </int></int>
The above is the detailed content of ASP.NET code easily implements WeChat grabbing red envelopes. For more information, please follow other related articles on the PHP Chinese website!