亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home php教程 php手冊(cè) 大家在搶紅包,程序員在研究紅包算法

大家在搶紅包,程序員在研究紅包算法

Jun 06, 2016 pm 07:45 PM
WeChat red envelope

微信紅包在春節(jié)的火爆程度不言而喻,廣告主投入5億現(xiàn)金紅包,與央視羊年春晚獨(dú)家合作起到了巨大的推動(dòng)作用。這就像一針大補(bǔ)丸,在短時(shí)間內(nèi)給微信帶來(lái)了極大的關(guān)

除夕全天微信用戶紅包總發(fā)送量達(dá)到10.1億次,搖一搖互動(dòng)量達(dá)到110億次,紅包峰值發(fā)送量為8.1億次/分鐘。

拋開微信紅包的市場(chǎng)價(jià)值不談,紅包本身的算法也引發(fā)了熱議,由于官方?jīng)]有給出明確的說法,各家也是眾說紛紜,小編下面也為大家?guī)?lái)幾種分析。

首先看看數(shù)據(jù)分析帝

大多數(shù)人都做出自己的猜測(cè),這也是在不知道內(nèi)部隨機(jī)算法的時(shí)候的唯一選擇,但是大多數(shù)人沒有給出自己親自的調(diào)查結(jié)果。這里給出一份100樣本的調(diào)查抽樣樣本數(shù)據(jù),并提出自己的猜測(cè)。

1. 錢包錢數(shù)滿足截尾正態(tài)隨機(jī)數(shù)分布。大致為在截尾正態(tài)分布中取隨機(jī)數(shù),并用其求和數(shù)除以總價(jià)值,獲得修正因子,再用修正因子乘上所有的隨機(jī)數(shù),得到紅包價(jià)值。

這種分布意味著:低于平均值的紅包多,但是離平均值不遠(yuǎn);高于平均值的紅包少,但是遠(yuǎn)大于平均值的紅包偏多。

大家在搶紅包,程序員在研究紅包算法


圖1. 錢包價(jià)值與其頻率分布直方圖及其正態(tài)擬合

但看分布直方圖并不能推出它符合正態(tài)分布,但是考慮到程序的簡(jiǎn)潔性和隨機(jī)數(shù)的合理性,這是最合乎情理的一種猜測(cè)。
越是后面的錢包,價(jià)值普遍更高

大家在搶紅包,程序員在研究紅包算法


圖2. 錢包序列數(shù)與其價(jià)值關(guān)系曲線

從圖2中的線性擬合紅線可以看到,錢包價(jià)值的總體變化趨勢(shì)是在慢慢增大,其變化范圍大約是一個(gè)綠色虛線上下界劃出的“通道”。(曲線可以被圍在這么一個(gè)正合乎常規(guī)的“通道”中,也從側(cè)面反映了規(guī)律1的合理性,說明了并不是均勻分布的隨機(jī)數(shù))
從另一個(gè)平均數(shù)的圖中也可以看出這一規(guī)律。

大家在搶紅包,程序員在研究紅包算法


圖3. 平均數(shù)隨序列數(shù)的變化曲線

在樣本中,1000價(jià)值的錢包被分成100份,均值為10。然而在圖3中我們可以看到在最后一個(gè)錢包之前,平均數(shù)一直低于10,這就說明了一開始的錢包價(jià)值偏低,一直被后期的錢包價(jià)值拉著往上走,后期的錢包價(jià)值更高。

3. 當(dāng)然平均數(shù)的圖還可以透露出另一個(gè)規(guī)律,那就是最后的那一個(gè)人往往容易走運(yùn)抽得比較多。因?yàn)樽詈竽且粋€(gè)人是錢包剩下多少就拿多少的,而之前所有人的平均數(shù) 都低于10,所以至少保證了最后一個(gè)人會(huì)高于平均值。在本樣本中,98號(hào)錢包抽到35,而最后一份錢包抽到46。

綜上,根據(jù)樣本猜測(cè):

大家在搶紅包,程序員在研究紅包算法


1. 抽到的錢大多數(shù)時(shí)候跟別人一樣少,但一旦一多,就容易多很多。
2. 越是抽后面的錢包,錢越容易多。
3. 最后一個(gè)人往往容易撞大運(yùn)。

點(diǎn)評(píng):這種明顯很實(shí)際有差異,小編每次不管什么時(shí)候搶都是幾毛錢。

第二位同學(xué)寫了一個(gè)簡(jiǎn)單python 代碼

據(jù)觀察,紅包分錢滿足以下幾點(diǎn):

1.不會(huì)有人拿不到錢

2.不會(huì)提前分完

3.錢的波動(dòng)范圍很大

紅包在一開始創(chuàng)建的時(shí)候,分配方案就訂好了。搶紅包的時(shí)候,,不過是挨個(gè)pop up而已。

因此 python 代碼如下:

def weixin_divide_hongbao(money, n): divide_table = [random.randint(1, 10000) for x in xrange(0, n)] sum_ = sum(divide_table) return [x*money/sum_ for x in divide_table]

不過上述算法還有兩個(gè)小問題:

1.浮點(diǎn)數(shù)精度問題

2.邊界值的處理

第三位同學(xué)按照網(wǎng)上流傳的python寫了一個(gè)java的版本

int j=1; while(j

第四位同學(xué)的這種算法看起來(lái)非常科學(xué)。

他認(rèn)為:

1、每個(gè)人都要能夠領(lǐng)取到紅包;

2、每個(gè)人領(lǐng)取到的紅包金額總和=總金額;

3、每個(gè)人領(lǐng)取到的紅包金額不等,但也不能差的太離譜,不然就沒趣味;

4、算法一定要簡(jiǎn)單,不然對(duì)不起騰訊這個(gè)招牌;

正式編碼之前,先搭建一個(gè)遞進(jìn)的模型來(lái)分析規(guī)律

設(shè)定總金額為10元,有N個(gè)人隨機(jī)領(lǐng)?。?br>

N=1

則紅包金額=X元;

N=2

為保證第二個(gè)紅包可以正常發(fā)出,第一個(gè)紅包金額=0.01至9.99之間的某個(gè)隨機(jī)數(shù)

第二個(gè)紅包=10-第一個(gè)紅包金額;

N=3

紅包1=0.01至0.98之間的某個(gè)隨機(jī)數(shù)

紅包2=0.01至(10-紅包1-0.01)的某個(gè)隨機(jī)數(shù)

紅包3=10-紅包1-紅包2

……

int j=1; while(j

輸入一看,波動(dòng)太大,這數(shù)據(jù)太無(wú)趣了!

第1個(gè)紅包:7.48 元,余額:2.52 元

第2個(gè)紅包:1.9 元,余額:0.62 元

第3個(gè)紅包:0.49 元,余額:0.13 元

第4個(gè)紅包:0.04 元,余額:0.09 元

第5個(gè)紅包:0.03 元,余額:0.06 元

第6個(gè)紅包:0.03 元,余額:0.03 元

第7個(gè)紅包:0.01 元,余額:0.02 元

第8個(gè)紅包:0.02 元,余額:0 元

改良一下,將平均值作為隨機(jī)安全上限來(lái)控制波動(dòng)差

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
What is the maximum amount of WeChat red envelopes that can be sent? What is the maximum amount of WeChat red envelopes that can be sent? Feb 23, 2024 pm 04:40 PM

What is the maximum amount of WeChat red envelopes that can be sent? There is an upper limit on the amount of red envelopes sent in WeChat, and some users are not clear about the maximum amount of red envelopes that can be sent on WeChat. The maximum amount on non-special dates is 200. Next is an introduction to the maximum amount of red envelopes that the editor brings to users. Interested users can come and take a look! WeChat usage tutorial How to set WeChat status background image Answer: 200 yuan Details: 1. The upper limit of WeChat red envelope amount: 200. Each person can only send a maximum of 200 yuan in WeChat red envelopes each time. 2. Special red envelope amount: On May 20 of each year, users can send red envelopes with an upper limit of 520 yuan.

How to return a WeChat red envelope? How to reject a WeChat red envelope and return it immediately to the other party? How to return a WeChat red envelope? How to reject a WeChat red envelope and return it immediately to the other party? Feb 22, 2024 pm 04:43 PM

The current WeChat red envelope does not support manual return. Tutorial Applicable Model: iPhone13 System: iOS15.5 Version: WeChat 8.0.19 Analysis 1 The current WeChat red envelope does not support manual return. For WeChat red envelopes that have not been claimed, the WeChat system will automatically return it to the originating account after 24 hours, so when If we want to return the red envelope after receiving it, as long as we don't accept it, it will be automatically returned after 24 hours. Supplement: How to return a WeChat transfer 1 Click on the transfer that needs to be returned on the WeChat chat interface. 2In the transfer details interface, click the refund option. 3. In the new pop-up window that appears, click Return again. Summary/Notes: The current WeChat red envelope does not support manual return. When we receive the red envelope, as long as we do not accept it, it will be returned after 24 hours.

How to return WeChat red envelope? How to handle the return of WeChat red envelopes How to return WeChat red envelope? How to handle the return of WeChat red envelopes Mar 12, 2024 pm 05:00 PM

WeChat is a mobile application that integrates social networking, payment, shopping and other functions, and is deeply loved by users. Among them, WeChat red envelopes, as part of the payment function, have won the favor of the majority of users for their convenience and fun. However, sometimes we may encounter situations where the wrong red envelope is sent. Although it is sometimes troublesome to return WeChat red envelopes, when using WeChat red envelopes, please be sure to check the information carefully to ensure that each sending is accurate. How to return WeChat red envelope? How to handle the return of WeChat red envelopes The return method of WeChat red envelopes mainly depends on whether the red envelope has been received. If the red envelope has not been received, there are the following handling methods: In case 1, if the other party has not received the red envelope, you can directly communicate with the other party, inform them that the wrong red envelope was sent, and ask the other party not to receive it. more than 24 hours

Detailed steps for returning WeChat red envelopes Detailed steps for returning WeChat red envelopes Mar 25, 2024 am 11:21 AM

1. Find the WeChat applet: 2. Click to search [Tencent Report Acceptance Center]. 3. Click on the option of Internet fraud. 4. Enter relevant information and screenshots. WeChat red envelope instructions: 1. If the WeChat red envelope is not collected within 24 hours, it will be returned directly. 2. WeChat red envelopes are collected by others and cannot be returned by you;

Specific methods for setting reminders for WeChat red envelopes Specific methods for setting reminders for WeChat red envelopes Mar 25, 2024 pm 05:46 PM

1. Download Tencent Butler 2. Find Tencent Mobile Butler: [Utility] - [More]. 3. Then click [Red Envelope Alarm Clock]. 4. When you see the options for WeChat and QQ, click one button below to open them. 5. Then you can see the interface after opening, or you can click the settings button in the upper right corner to set it. 6. You can choose sound reminders or vibration reminders, and you can set them all.

What is the maximum number of red envelopes that can be sent on WeChat? What is the maximum number of red envelopes that can be sent on WeChat? Aug 17, 2023 pm 01:48 PM

You can send up to 200 red envelopes on WeChat. Details: The total amount of red envelopes sent to each user per day cannot exceed 1,000 yuan. Although there are some limitations, WeChat red envelopes are still a very convenient and popular payment method. Whether during the Chinese New Year or on other special occasions, WeChat red envelopes bring more fun and surprises to people.

A detailed explanation of the prompts for returning WeChat red envelopes to the other party A detailed explanation of the prompts for returning WeChat red envelopes to the other party Mar 25, 2024 pm 05:51 PM

1. First, we open WeChat and click on the search box. 2. Search for WeChat Pay 3. Click to enter. 4. Both parties will have WeChat red envelope refund prompts here.

How to set the WeChat red envelope notification sound? How to set the WeChat red envelope prompt sound How to set the WeChat red envelope notification sound? How to set the WeChat red envelope prompt sound Mar 13, 2024 am 11:30 AM

WeChat, as a feature-rich social application, not only provides people with a convenient way to communicate, but also adds more fun through its unique red envelope function. Setting the WeChat red envelope notification sound will allow users to know immediately when receiving a red envelope, adding anticipation and surprise. The setting of the WeChat red envelope reminder sound makes every time you receive a red envelope full of anticipation and fun. The setting method of WeChat red envelope notification sound mainly depends on your mobile phone system and WeChat version. Let’s take a look at the setup steps for Android and Apple systems. How to set the WeChat red envelope notification sound? Method 1 for setting the WeChat red envelope prompt sound. For Android system, 1. Open the WeChat application, click the [Me] option in the bottom navigation bar, enter the [Me] page, and then click [Settings]. 2. On the settings page

See all articles