ASP.NET code easily implements WeChat grabbing red envelopes

高洛峰
Release: 2017-03-31 15:21:42
Original
3354 people have browsed it

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

 

ASP.NET code easily implements WeChat grabbing red envelopesASP.NET code easily implements WeChat grabbing red envelopesASP.NET code easily implements WeChat grabbing red envelopesASP.NET code easily implements WeChat grabbing red envelopes

50 yuan and 13 red envelopes

 

ASP.NET code easily implements WeChat grabbing red envelopesASP.NET code easily implements WeChat grabbing red envelopesASP.NET code easily implements WeChat grabbing red envelopesASP.NET code easily implements WeChat grabbing red envelopes ASP.NET code easily implements WeChat grabbing red envelopes

10 red envelopes per block

 

ASP.NET code easily implements WeChat grabbing red envelopesASP.NET code easily implements WeChat grabbing red envelopesASP.NET code easily implements WeChat grabbing red envelopesASP.NET code easily implements WeChat grabbing red envelopesASP.NET code easily implements WeChat grabbing red envelopes

The following conditions need to be met for sending red envelopes

1. The total amount remains unchanged

2. 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 13. Remainder processing, when the data is averaged to 20 red envelopes, it must be different from the total amount. Deviation, at this time we have to refund more and make up less. If it is greater than the total amount, let the one with the larger amount reduce it (total amount/total number of people). If there is still something left, let the one with the second largest amount reduce it until this is completed. Until there is a vacancy, and vice versa.
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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!