关于定时刷票的一个算法问题

WBOY
Release: 2016-06-23 14:20:40
Original
1191 people have browsed it

关于一个定时刷票的问题,场景如下:
某个时段内投N个票,如设置一个小时刷2000张票!则一小时内会多次对其投票,且每次投票的数量是随机的(当然总投票数量不能超过刚才说的总数2000),如何将其分解成一条条的任务呢。

如:
1. 10点投5票
2. 10点零9分投7票
3. 10点20分投200票
4. 10点22分投10票
5. 。。。。
6. 11点投N分。

谢谢!


回复讨论(解决方案)

思路

total = 2000; //总数$num = 20; //批数for($i=0; $i<$num; $i++) {  if($total) {    $n = $i+1 == $num ? $total : rand(0, $total*($i+1)/$num);    echo $n, PHP_EOL;    $total -= $n;  }}
Copy after login

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!