In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to understand random algorithm". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
Let's look at the data analysis first.
Most people make their own guesses, which are the only choices when they don't know the internal random algorithm, but most people don't give their own findings. Here is a sample of 100 survey samples and my guess.
1. Wallet money satisfies a truncated normal random number distribution. Roughly, take random numbers in the truncated normal distribution, divide the sum by the total value, obtain the correction factor, and then multiply all random numbers by the correction factor to obtain the red envelope value.
This distribution means that there are more red packets below the average, but not far from the average; there are fewer red packets above the average, but more red packets far above the average.
Figure 1. Histogram of wallet value and its frequency distribution and its normal fitting
But looking at the distribution histogram doesn't lead to a normal distribution, but considering the simplicity of the program and the rationality of random numbers, this is the most reasonable guess.
The later the wallet, the higher the value.
Figure 2. Curve of the relationship between the number of wallet series and its value
As can be seen from the linear fit red line in Figure 2, the overall trend of wallet value is slowly increasing, and its range of variation is approximately the "channel" delineated by the upper and lower boundaries of a green dashed line. (The curve can be enclosed in such a conventional "channel", which also reflects the rationality of Law 1 from the side, indicating that random numbers are not uniformly distributed)
This pattern can also be seen in another graph of averages.
Figure 3. curve of average number changing with number of series
In the sample, a wallet worth 1000 was divided into 100, with an average of 10. In Figure 3, however, we can see that the average is below 10 until the last wallet, indicating that the initial wallet value is low and has been pulled up by the later wallet value, which is higher.
3. Of course, the graph of averages can also reveal another rule, that is, the last person tends to be lucky to draw more. Because the last person gets what's left of his wallet, and everyone else's average is below 10, at least the last person is guaranteed to be above average. In this sample, wallet number 98 drew 35, while the last wallet drew 46.
In summary, based on the sample guess:
1. Most of the time, the money drawn is as small as others, but once it is more, it is easy to get more.
2. The more you pull out the back of your wallet, the easier it is to get more money.
3. The last one always gets lucky.
Comments: This is obviously very practical difference, Xiaobian every time no matter when to rob is a few cents.
The second student wrote a simple python code
It has been observed that the red envelope cent satisfies the following points:
1. No one gets paid.
2. It won't be finished early.
3. Money fluctuates widely.
When the red envelope was created at the beginning, the distribution plan was set up. When it comes to red packets, it's just pop up one by one.
So Python code is as follows:
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]
However, there are two minor problems with the above algorithm:
1. floating point precision problem
2. Treatment of boundary values
The third student wrote a version of java according to python circulating on the Internet
int j=1; while(j
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.