這篇文章主要為大家相許介紹了輕鬆實現微信搶紅包的ASP.NET程式碼,具有一定的參考價值,有興趣的小夥伴們可以參考一下
群組裡都在玩搶紅包,搶了再發,發了再搶,簡直是無聊,程式設計師感興趣是的如何實現,這裡簡單說說實現思路,附上dome,代碼有點low,好在是實現了,具體內容如下
正文
100塊發送30個紅包
50塊發13個紅包
實現想法1.首先要確定最小單位,這裡是精確到分,我這裡以int類型進行計算,得出的結果也全是int型別
2.資料均勻,這裡以 1
4.打亂順序,細心的園友可能發現,紅包是有順序規律的,我們必須簡單的寫個function去打亂它.
#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>
以上是ASP.NET程式碼輕鬆實現微信搶紅包的詳細內容。更多資訊請關注PHP中文網其他相關文章!