之前有一个任务,其中一个步骤是从名单中随机选择部分用户去执行一些操作,而且要保证用户被选中的概率大致相等。  (图源:[pixabay](https://pixabay.com)) # `random.randint()` 我对Python不是很熟,所以我首先想到的是用random生成列表长度范围内的随机数,然后再用下标的方式去读取列表。 为了记录操作次数以比较列表元素被选中的概率,我将列表改成字典的形式,以便于记录操作次数。 ##### 代码如下: ``` import time import random from pprint import pprint dict= {'a':0, 'b':0, 'c':0, 'd':0} list = list(dict.keys()) pprint(dict) pprint(list) start = time.clock() for i in range(0, 400000): index = random.randint(0, 3) dict[list[index]]+=1 pprint(dict) print("CPU Time:", time.clock() - start) ``` ##### 执行结果如下:  可以看到元素被选中的概率基本相同,可以满足我们的需求。 # `random.choice()` 上述代码虽然能实现功能,但是总感觉不是很优雅,经过查手册,发现了random.choice()这个函数,来试试这个吧。 ##### 代码如下: ``` import time import random from pprint import pprint dict= {'a':0, 'b':0, 'c':0, 'd':0} list = list(dict.keys()) pprint(dict) pprint(list) start = time.clock() for i in range(0, 400000): choice = random.choice(list) dict[choice]+= 1 pprint(dict) print("CPU Time:", time.clock() - start) ``` ##### 执行结果结果如下:  可以看出元素被选中的概率基本相同,但是***就性能而言,比random.randint()方法要好很多.*** # `random.sample()` 有发现random模块居然还有个sample函数,看起来专门为取样设计的啊 代码如下: ``` import time import random from pprint import pprint dict= {'a':0, 'b':0, 'c':0, 'd':0} list = list(dict.keys()) pprint(dict) pprint(list) start = time.clock() for i in range(0, 400000): samples = random.sample(list, 1) dict[samples[0]]+= 1 pprint(dict) print("CPU Time:", time.clock() - start) ``` ##### 执行结果结果如下:  OMG, 尽管元素被选中的概率基本相同,但***这性能哭了***。(当然,可能耗费在列表元素读取上,具体是啥,懒得评估了),看来名字好看也不一定中用啦。 # `random.choices()` 咦,又发现一个崭新的函数,之所以说它是崭新的,是因为这是在3.6版本中新增的函数 ***New in version 3.6*** 如果你还在运行3.6以下版本,对不起,这个你用不了。 ##### 代码如下: ``` import time import random from pprint import pprint dict= {'a':0, 'b':0, 'c':0, 'd':0} list = list(dict.keys()) pprint(dict) pprint(list) start = time.clock() for i in range(0, 400000): choices = random.choices(list, k=1) dict[choices[0]]+= 1 pprint(dict) print("CPU Time:", time.clock() - start) ``` ##### 执行结果结果如下:  哇,你看看人家,要结果有结果,要颜值有颜值,要性能有性能,简直完美的不要不要的。 # 更进一步 从上边的结果,不能看出,选取结果***概率都是均匀分布的***,符合我们的要求。 但是选择一个元素的时候, ***`random.choice()`函数性能最好***。 那么我们为何还要大力推崇***`random.choices() `***呢?答案有两点: * 支持选择多个元素 * 支持设置不同元素权重 ##### 支持选择多个元素 代码: ``` import time import random from pprint import pprint dict= {'a':0, 'b':0, 'c':0, 'd':0} list = list(dict.keys()) pprint(dict) pprint(list) start = time.clock() for i in range(0, 400000): choices = random.choices(list, k=2) dict[choices[0]]+= 1 dict[choices[1]]+= 1 pprint(dict) print("CPU Time:", time.clock() - start) ``` 结果:  看吧,选择了2倍量的元素,耗时只增加了一丁点。 ##### 支持设置不同元素权重 如果想让不同的元素,被选取的概率不同,我之前的做法是这样的 把`['a', 'b', 'c', 'd'] `改成`['a', 'a', 'b', 'c', 'd']`,是不是看起来傻,我觉得也是! 正确是姿势是用***`random.choices()`***并设置***权重/weights*** 的方法 代码: ``` import time import random from pprint import pprint dict= {'a':0, 'b':0, 'c':0, 'd':0} list = list(dict.keys()) pprint(dict) pprint(list) start = time.clock() for i in range(0, 400000): choices = random.choices(list, [2, 2, 1, 3], k=2) dict[choices[0]]+= 1 dict[choices[1]]+= 1 pprint(dict) print("CPU Time:", time.clock() - start) ``` 结果:  完美的不要不要的,有没有? 听说用cum_weights参数,效率会更高,比如改成这样: ***`choices = random.choices(list, cum_weights=[2, 4, 5, 8], k=2)`*** 试了一下,果然性能提升了不少,不过我决定坚决弃用,为何? 不直观呗! # 总结 / Summaries 通过学习,我们知道在Python 中,可以用下列函数随机选取元素 * ***`random.randint()`*** * ***`random.choice()`*** * ***`random.sample()`*** * ***`random.choices()`*** 通过测试,我们发现最后一个函数可以用来***选取多个元素***,并且***支持设置权重,性能也是极佳***。以后就用它啦。 --- 之所以做这个测试,是因为我的一段程序中原本用的***`random.sample()`***,但是选中的元素明显概率不一样,后来我改写了程序其它部分,并改用***`random.choices()`***,概率分布效果极佳。 但是我觉得***`random.sample()`***不应该存在概率问题啊,于是写了上述几段程序测试了一下,发现并不存在所谓概率的问题。看来我冤枉***`random.sample()`***了,是我其它代码导致的问题, 但是发现***`random.choices()`果然是最佳选择***。
author | oflyhigh |
---|---|
permlink | python-cny |
category | cn |
json_metadata | {"tags":["cn","cn-programming","python","random","sample"],"image":["https://steemitimages.com/DQmcQ9NjUGYTynLd8gKfDk4EMjYm8sHvPHZf9TjezST4ZT1/cube-442544_1280.jpg","https://steemitimages.com/DQmdqQscNQVNFvPRFhMzfm63SqvuJsp99Vo3uo5iUnzFtZb/image.png","https://steemitimages.com/DQmbopy42JDCqkUPYJV13QSwAXeN9dbAhTQDfQrSJpoTpYM/image.png","https://steemitimages.com/DQmWNpR6r5qqBJE6xxn19KR1XqQMGEhqrPxCuC2MapvMqN4/image.png","https://steemitimages.com/DQmWyVt8grpsy9366hZid4zehaMrE7Q1W3v637fYzWEsrP6/image.png","https://steemitimages.com/DQmRd16RDMRFmUphGECwNY3R7C5qw7yZvBHL9EgXjjrzmWD/image.png","https://steemitimages.com/DQmNjEH9vQDm63rpFLo8ZcqzMKNMLQtGFK1W8DayWJ2dNbS/image.png"],"links":["https://pixabay.com"],"app":"steemit/0.1","format":"markdown"} |
created | 2017-09-28 11:22:39 |
last_update | 2017-09-28 11:22:39 |
depth | 0 |
children | 19 |
last_payout | 2017-10-05 11:22:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 198.996 HBD |
curator_payout_value | 46.945 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.010 HBD |
body_length | 4,488 |
author_reputation | 6,269,730,276,883,447 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,172,564 |
net_rshares | 85,537,174,544,388 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
xeldal | 0 | 54,388,973,921 | 0.3% | ||
pharesim | 0 | 102,954,031,559 | 0.03% | ||
enki | 0 | 13,041,919,746 | 0.3% | ||
abit | 0 | 24,795,301,935,002 | 55% | ||
boy | 0 | 297,900,321 | 100% | ||
bue-witness | 0 | 363,239,134 | 100% | ||
bunny | 0 | 62,095,939 | 100% | ||
bue | 0 | 81,834,651,623 | 100% | ||
mini | 0 | 159,222,777 | 100% | ||
healthcare | 0 | 69,227,063 | 100% | ||
daniel.pan | 0 | 93,873,289 | 100% | ||
nomoreheroes7 | 0 | 295,358,280 | 1% | ||
jademont | 0 | 218,610,975,576 | 100% | ||
gavvet | 0 | 188,114,907,091 | 1% | ||
cryptoctopus | 0 | 69,868,296,417 | 1% | ||
steve-walschot | 0 | 286,831,954 | 1% | ||
dragonslayer109 | 0 | 21,322,114,479 | 1% | ||
coinbitgold | 0 | 177,484,804,959 | 80% | ||
rok-sivante | 0 | 1,275,171,845,901 | 100% | ||
mike-mike | 0 | 1,306,075,111 | 100% | ||
wongshiying | 0 | 29,367,288,564 | 100% | ||
grandpere | 0 | 2,340,398,370 | 1% | ||
knopki | 0 | 82,483,898 | 10% | ||
geoffrey | 0 | 1,214,410,859,153 | 70% | ||
robrigo | 0 | 263,716,971,758 | 100% | ||
slowwalker | 0 | 1,633,684,253,805 | 15% | ||
vi1son | 0 | 135,369,097,883 | 100% | ||
jacor | 0 | 4,167,987,355 | 1% | ||
livingfree | 0 | 2,287,284,024,156 | 25% | ||
freeyourmind | 0 | 2,392,350,859,092 | 100% | ||
gikitiki | 0 | 477,784,794 | 2% | ||
blockchainbilly | 0 | 12,433,396,023 | 50% | ||
biophil | 0 | 29,941,527,509 | 100% | ||
fundurian | 0 | 32,407,903,452 | 25% | ||
arcange | 0 | 31,423,371,641 | 10% | ||
deanliu | 0 | 717,872,217,740 | 100% | ||
rea | 0 | 291,884,710,255 | 25% | ||
neroru | 0 | 1,546,286,156 | 5% | ||
crazymumzysa | 0 | 1,586,706,286 | 1% | ||
raphaelle | 0 | 5,029,462,449 | 10% | ||
joythewanderer | 0 | 141,991,743,906 | 40% | ||
lemooljiang | 0 | 40,679,744,509 | 10% | ||
emilhoch | 0 | 236,667,658,055 | 25% | ||
ace108 | 0 | 396,943,315,207 | 25% | ||
craigslist | 0 | 53,534,085 | 100% | ||
magicmonk | 0 | 34,626,250,155 | 100% | ||
laoyao | 0 | 31,965,023,776 | 100% | ||
cryptoninja | 0 | 169,606,435 | 2% | ||
somebody | 0 | 1,322,504,225,756 | 100% | ||
feelapi | 0 | 3,285,104,766 | 60% | ||
timsaid | 0 | 121,234,929,839 | 1% | ||
midnightoil | 0 | 175,985,273,586 | 100% | ||
btsabc | 0 | 110,889,641,747 | 100% | ||
snowflake | 0 | 2,438,377,999,870 | 100% | ||
xiaohui | 0 | 909,811,659,400 | 100% | ||
silentlucidity53 | 0 | 2,191,618,727 | 75% | ||
oflyhigh | 0 | 2,375,883,636,440 | 100% | ||
xiaokongcom | 0 | 15,404,358,042 | 100% | ||
hanshotfirst | 0 | 160,389,656,416 | 5% | ||
rivalhw | 0 | 612,727,604,921 | 49% | ||
nextgen622 | 0 | 641,880,461,311 | 100% | ||
chinadaily | 0 | 208,854,257,212 | 100% | ||
helene | 0 | 308,729,166,674 | 100% | ||
fred703 | 0 | 225,571,841 | 1% | ||
ffcrossculture | 0 | 20,249,224,356 | 100% | ||
ethansteem | 0 | 354,917,120,914 | 100% | ||
sweetsssj | 0 | 2,983,741,345,026 | 10% | ||
tumutanzi | 0 | 1,062,315,123,257 | 6% | ||
englishtchrivy | 0 | 164,471,246,588 | 50% | ||
ivet | 0 | 36,887,459,149 | 50% | ||
shieha | 0 | 3,133,590,734 | 100% | ||
profitgenerator | 0 | 3,289,052,290 | 100% | ||
ebargains | 0 | 634,290,759 | 10% | ||
bitcointr | 0 | 117,111,895 | 100% | ||
jessicanicklos | 0 | 2,556,287,251 | 12% | ||
funnyman | 0 | 1,448,909,951 | 0.2% | ||
justyy | 0 | 85,629,308,471 | 42.18% | ||
arama | 0 | 3,931,676,134,808 | 80% | ||
stacee | 0 | 117,816,926,394 | 100% | ||
luneknight | 0 | 1,242,284,862 | 100% | ||
yuxi | 0 | 2,928,400,310 | 50% | ||
steemtruth | 0 | 42,915,570,578 | 10% | ||
lalala | 0 | 57,067,980,070 | 100% | ||
graviton | 0 | 465,779,598 | 1% | ||
keuudeip | 0 | 117,782,385 | 0.1% | ||
dapeng | 0 | 15,794,925,596 | 100% | ||
happyukgo | 0 | 587,563,998 | 35% | ||
utmaster | 0 | 2,623,802,407 | 100% | ||
johnrenald | 0 | 3,582,154,379 | 100% | ||
ruthofisrael | 0 | 327,878,015 | 1% | ||
devilwsy | 0 | 2,349,649,310 | 100% | ||
janiceting | 0 | 2,347,439,190 | 100% | ||
ozymandias | 0 | 2,184,757,117 | 100% | ||
lydiachan | 0 | 20,563,910,108 | 100% | ||
harferri | 0 | 91,032,214 | 1% | ||
dragon40 | 0 | 2,638,655,108 | 10% | ||
dkulik77 | 0 | 1,614,909,101 | 100% | ||
someonewhoisme | 0 | 2,389,293,084,463 | 100% | ||
lucknie | 0 | 10,778,623,992 | 100% | ||
jackhircus | 0 | 57,230,080,298 | 80% | ||
blackbunny | 0 | 113,861,595,074 | 100% | ||
jubi | 0 | 109,993,143,668 | 100% | ||
chessmasterhex | 0 | 3,388,186,102 | 100% | ||
bxt | 0 | 112,411,896,055 | 100% | ||
lingfei | 0 | 92,531,886,595 | 100% | ||
yyyy | 0 | 45,320,406,880 | 100% | ||
mandela | 0 | 2,130,726,585 | 1% | ||
vikx | 0 | 10,150,475,076 | 100% | ||
coldhair | 0 | 89,527,324,212 | 50% | ||
trafalgar | 0 | 2,474,834,255,569 | 12% | ||
oluwoleolaide | 0 | 323,363,089 | 0.1% | ||
fernwehninja | 0 | 507,258,656 | 2% | ||
avika | 0 | 1,321,918,031 | 100% | ||
austinsandersco | 0 | 64,396,383,352 | 70% | ||
aismor | 0 | 805,633,232 | 100% | ||
marxrab | 0 | 3,658,008,497 | 8% | ||
hammadakhtar | 0 | 942,408,313 | 10% | ||
luna33 | 0 | 154,852,992,064 | 100% | ||
danlupi | 0 | 13,548,682,890 | 1% | ||
htliao | 0 | 5,156,679,588,106 | 33% | ||
gordonovich | 0 | 994,408,223 | 5% | ||
aarkay | 0 | 323,771,916 | 100% | ||
redpill | 0 | 472,298,026 | 1% | ||
clodoweg | 0 | 4,237,342,381 | 100% | ||
manuel78 | 0 | 108,785,614 | 1% | ||
tellall | 0 | 518,581,861 | 100% | ||
mandagoi | 0 | 14,590,313,578 | 21% | ||
indiantraveller | 0 | 115,371,458 | 0.06% | ||
ribalinux | 0 | 5,974,891,259 | 22% | ||
stackin | 0 | 15,674,451,590 | 1% | ||
jerrybanfield | 0 | 367,277,148,134 | 20% | ||
ojaber | 0 | 29,987,256,014 | 100% | ||
wylo | 0 | 636,033,067 | 100% | ||
followbtcnews | 0 | 3,302,766,304 | 5% | ||
jkkim | 0 | 21,353,651,820 | 10% | ||
ebejammin | 0 | 624,649,906,124 | 100% | ||
kenchung | 0 | 35,126,721,124 | 100% | ||
wallsnow | 0 | 436,553,762 | 100% | ||
happychau123 | 0 | 10,136,271,186 | 100% | ||
linuslee0216 | 0 | 7,927,898,898,047 | 41% | ||
revelim | 0 | 7,791,258,225 | 30% | ||
josearteaga | 0 | 71,728,429 | 100% | ||
cryptohustler | 0 | 4,063,157,891 | 100% | ||
safran | 0 | 5,483,922,623 | 100% | ||
benderisgreat | 0 | 682,141,767 | 100% | ||
wilkinshui | 0 | 74,404,016,259 | 100% | ||
arsar | 0 | 620,345,897 | 100% | ||
drwom | 0 | 25,320,582,964 | 30% | ||
exec | 0 | 82,641,398,143 | 100% | ||
eval | 0 | 827,011,129 | 100% | ||
aliyah2017 | 0 | 70,719,749,887 | 100% | ||
speeding | 0 | 921,915,432 | 100% | ||
kuldeepkaul | 0 | 145,587,200 | 100% | ||
shenchensucc | 0 | 18,087,061,821 | 100% | ||
walkinharmony | 0 | 13,514,622,586 | 90% | ||
othniel | 0 | 895,257,380 | 100% | ||
asterix87 | 0 | 14,442,159,662 | 100% | ||
nataliejohnson | 0 | 3,094,108,487 | 5% | ||
tandemus | 0 | 1,364,789,377 | 100% | ||
cheeto.blue | 0 | 192,474,666 | 0.1% | ||
abetterworld | 0 | 4,258,698,581 | 100% | ||
gentlebot | 0 | 201,399,124,300 | 100% | ||
ldauch | 0 | 9,483,675,768 | 100% | ||
fenghuang | 0 | 4,777,033,570,496 | 100% | ||
thing-2 | 0 | 200,585,584,338 | 100% | ||
goldkey | 0 | 10,010,021,150 | 10% | ||
sweeti | 0 | 108,270,009,763 | 100% | ||
that1consultant | 0 | 9,063,154,443 | 100% | ||
sanzo | 0 | 504,585,805 | 100% | ||
stenyin | 0 | 622,326,305 | 100% | ||
davaowhenyo | 0 | 620,139,483 | 100% | ||
allenshayzar | 0 | 619,520,000 | 100% | ||
travelgirl | 0 | 55,395,304,124 | 100% | ||
martinbrandow | 0 | 1,964,388,733 | 100% | ||
raku | 0 | 893,610,490 | 100% | ||
resteeming | 0 | 413,662,087 | 100% | ||
ahmadakhirat | 0 | 1,216,321,133 | 100% | ||
ravenousappetite | 0 | 619,520,000 | 100% | ||
aabb | 0 | 410,728,692 | 100% | ||
catwomanteresa | 0 | 41,647,065,520 | 100% | ||
auntigormint | 0 | 1,485,894,548 | 100% | ||
mrliga | 0 | 9,833,622,501 | 100% | ||
angela.ghkh | 0 | 855,035,080 | 100% | ||
hannahwu | 0 | 5,935,166,107 | 93% | ||
twinkledrop | 0 | 89,140,186,838 | 100% | ||
cheonillhwan | 0 | 807,410,306 | 100% | ||
nicolemoker | 0 | 4,155,623,873,355 | 20% | ||
negojobs | 0 | 442,223,295 | 100% | ||
davidzack | 0 | 490,816,806 | 100% | ||
bosveldtzaneen | 0 | 608,407,338 | 100% | ||
academix87 | 0 | 1,022,746,269 | 100% | ||
khalilulhadi | 0 | 783,181,659 | 100% | ||
drunkevil | 0 | 6,240,623,533 | 100% | ||
sweethoney | 0 | 595,316,213 | 100% | ||
aungmyotun | 0 | 370,795,210 | 44.64% | ||
duekie | 0 | 481,057,321 | 100% | ||
idx | 0 | 10,395,545,008 | 55% | ||
exprmnt | 0 | 1,706,107,459 | 100% | ||
nurhasib | 0 | 108,679,708 | 100% | ||
modemser | 0 | 9,760,033,723 | 100% | ||
mudatnad | 0 | 140,180,332 | 100% | ||
jessicameng | 0 | 5,458,273,162 | 100% | ||
fr3eze | 0 | 13,109,103,776 | 80% | ||
leogor1234 | 0 | 5,002,992,933 | 100% | ||
aafeng | 0 | 13,638,900,106 | 100% | ||
herlife | 0 | 6,254,911,332 | 43% | ||
yunkard | 0 | 169,002,032 | 100% | ||
rabeel | 0 | 661,920,339 | 100% | ||
goldminevoyager | 0 | 778,053,743 | 100% | ||
saifullah05 | 0 | 737,005,794 | 100% | ||
vadimlasca | 0 | 1,020,701,771 | 100% | ||
freedom-fighter | 0 | 619,520,000 | 100% | ||
zainuddinibrahim | 0 | 1,144,831,717 | 100% | ||
yunxiaohui | 0 | 1,738,925,206 | 100% | ||
bobbyboe | 0 | 21,998,394,110 | 100% | ||
acactus1013 | 0 | 2,880,087,198 | 100% | ||
err0rist | 0 | 536,866,284 | 100% | ||
kypy24 | 0 | 379,637,071 | 100% | ||
yellowbird | 0 | 13,662,250,894 | 100% | ||
technologynepal | 0 | 1,160,638,332 | 100% | ||
funkie68 | 0 | 21,899,546,843 | 100% | ||
dgorbunov | 0 | 1,132,875,859 | 100% | ||
kanashimi | 0 | 60,719,890 | 5% | ||
have-a-nice-day | 0 | 246,770,905 | 20% | ||
tiffanyrej | 0 | 3,556,097,422 | 100% | ||
alishannoor | 0 | 1,912,048,225 | 100% | ||
khalilad | 0 | 660,364,151 | 100% | ||
ms8988 | 0 | 1,271,203,300 | 100% | ||
superbing | 0 | 2,305,522,993 | 35% | ||
dailyfortune | 0 | 1,372,593,869 | 35% | ||
antone | 0 | 1,015,550,838 | 100% | ||
hafidg | 0 | 1,015,197,295 | 100% | ||
oluwasegun | 0 | 297,458,802 | 100% | ||
space-man | 0 | 400,405,084 | 1% | ||
xiaoshancun | 0 | 283,650,426 | 100% | ||
dailystats | 0 | 1,380,846,518 | 35% | ||
raviraj | 0 | 7,785,924,899 | 100% | ||
sarcastic.man | 0 | 665,992,264 | 100% | ||
victory622 | 0 | 22,712,231,526 | 94% | ||
theassailant | 0 | 567,220,622 | 100% | ||
smartlogic | 0 | 2,137,117,074 | 100% | ||
nikkawesome | 0 | 487,461,534 | 100% | ||
speakingfreely | 0 | 1,032,432,496 | 100% | ||
etzel | 0 | 1,781,032,787 | 100% | ||
xj3000 | 0 | 724,030,613 | 100% | ||
kike93 | 0 | 0 | 100% | ||
monkeyplayfire | 0 | 864,659,825 | 100% | ||
brendashockley | 0 | 145,077,042 | 25% | ||
dennisphillips | 0 | 145,077,042 | 25% | ||
metten | 0 | 2,700,516,350 | 100% | ||
christophzak | 0 | 966,640,766 | 90% | ||
thenewforktimes | 0 | 676,635,417 | 100% | ||
vrushali15 | 0 | 645,840,388 | 100% | ||
gooday2live | 0 | 649,965,951 | 100% | ||
ikonik | 0 | 943,615,630 | 100% | ||
tamires | 0 | 451,838,132 | 100% | ||
vallettinni | 0 | 1,102,581,542 | 100% | ||
lemminon | 0 | 1,161,228,115 | 100% | ||
vandadream | 0 | 648,848,407 | 100% | ||
tonioni | 0 | 858,849,032 | 100% | ||
by-yesilbag | 0 | 1,931,074,214 | 100% | ||
byn-yesilbag | 0 | 1,544,027,167 | 100% | ||
mitchconnor | 0 | 1,161,430,479 | 100% | ||
steemmagnet | 0 | 951,730,643 | 100% | ||
jeeandmee | 0 | 791,139,102 | 100% | ||
shmiddy-dack | 0 | 677,650,623 | 100% | ||
dunatos | 0 | 1,010,479,438 | 100% | ||
nicholas83 | 0 | 1,179,046,949 | 100% | ||
bottomless1905 | 0 | 1,172,310,005 | 100% | ||
mahyul | 0 | 178,352,837 | 100% | ||
j-stark | 0 | 357,625,792 | 100% | ||
saqibhayat | 0 | 731,930,911 | 100% | ||
ashokpaleti | 0 | 690,556,308 | 100% | ||
ozertekdal | 0 | 1,114,174,846 | 100% | ||
annekul | 0 | 1,160,597,741 | 100% | ||
yavuzgul | 0 | 324,967,121 | 100% | ||
nomangtx | 0 | 841,432,643 | 100% | ||
sergey999 | 0 | 324,966,991 | 100% | ||
mingsg | 0 | 1,119,975,400 | 100% | ||
danisgat | 0 | 1,137,384,071 | 100% | ||
hymle | 0 | 1,038,733,226 | 100% | ||
tnydmr | 0 | 504,859,138 | 100% | ||
cnts | 0 | 394,479,292 | 100% | ||
joshua123 | 0 | 214,710,195 | 100% | ||
sams | 0 | 85,829,315 | 1% | ||
babakul | 0 | 1,160,593,577 | 100% | ||
aricyk | 0 | 249,527,584 | 100% | ||
roniakbar623 | 0 | 121,862,307 | 100% | ||
osos | 0 | 905,262,768 | 100% | ||
ruah | 0 | 75,438,555 | 100% | ||
bromedya | 0 | 992,306,694 | 100% | ||
crypticname | 0 | 765,990,887 | 100% | ||
hygge | 0 | 1,015,518,163 | 100% | ||
needcashnow | 0 | 1,032,927,035 | 100% | ||
mohbmz | 0 | 649,931,339 | 100% | ||
ryanbreavens | 0 | 887,852,515 | 100% | ||
prabhukhare | 0 | 290,147,738 | 100% | ||
cyrilk | 0 | 1,119,969,827 | 100% | ||
moe46 | 0 | 0 | 100% |

author | angela.ghkh |
---|---|
permlink | re-oflyhigh-python-cny-20170928t121752023z |
category | cn |
json_metadata | {"tags":["cn"],"image":["https://steemitimages.com/DQmfRtqv8Gqc8e8T89dsd4DwMy1RA71KR8UbTSGa6jbK9fM/image.png"],"app":"steemit/0.1"} |
created | 2017-09-28 12:17:57 |
last_update | 2017-09-28 12:17:57 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 12:17:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 88 |
author_reputation | 2,888,077,605,665 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,176,518 |
net_rshares | 0 |
 please vote
author | bosveldtzaneen |
---|---|
permlink | re-oflyhigh-python-cny-20170928t120436400z |
category | cn |
json_metadata | {"tags":["cn"],"image":["https://steemitimages.com/DQmTixdL7ubhZ8DqRu3TCxUJ3kDBcghHGwzbsYhAZZ2vQiZ/image.png"],"app":"steemit/0.1"} |
created | 2017-09-28 12:04:36 |
last_update | 2017-09-28 12:04:36 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 12:04:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 100 |
author_reputation | -464,352,257,115 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,175,422 |
net_rshares | 0 |
upvoted&followed, look at my photos :)
author | flowingpictures |
---|---|
permlink | re-oflyhigh-python-cny-20170928t120515090z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 12:05:18 |
last_update | 2017-09-28 12:05:18 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 12:05:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 38 |
author_reputation | 3,014,403,980 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,175,491 |
net_rshares | 0 |
Thanks for sharing. Good post. :) I'm following. Please follow me...
author | forexmaster |
---|---|
permlink | re-oflyhigh-python-cny-20170928t112352162z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 11:23:45 |
last_update | 2017-09-28 11:23:45 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 11:23:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 68 |
author_reputation | 219,144,842,817 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,172,638 |
net_rshares | 0 |
I read your article interesting.I look forward to seeing you.
author | hygge |
---|---|
permlink | re-oflyhigh-python-cny-20170928t121702282z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 12:17:06 |
last_update | 2017-09-28 12:17:06 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 12:17:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 61 |
author_reputation | 3,174,533,283,781 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,176,457 |
net_rshares | 0 |
> 其中一个步骤是从名单中随机选择部分用户去执行一些操作,而且要保证用户被选中的概率大致相等。 其实可以换个思路,先 random.shuffle 然后再取 前N 个。
author | justyy |
---|---|
permlink | re-oflyhigh-python-cny-20170930t003051726z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-30 00:30:54 |
last_update | 2017-09-30 00:32:27 |
depth | 1 |
children | 1 |
last_payout | 2017-10-07 00:30:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.617 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 86 |
author_reputation | 280,616,224,641,976 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,328,669 |
net_rshares | 225,220,097,579 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
justyy | 0 | 225,220,097,579 | 100% |
这也是思路之一 不过random.shuffle改变元素的位置 我想当然的认为它的效率会低,所以没有去测试 以后有时间测测看
author | oflyhigh |
---|---|
permlink | re-justyy-re-oflyhigh-python-cny-20170930t085121471z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-30 08:51:21 |
last_update | 2017-09-30 08:51:21 |
depth | 2 |
children | 0 |
last_payout | 2017-10-07 08:51:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 63 |
author_reputation | 6,269,730,276,883,447 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,357,488 |
net_rshares | 0 |
一個小小的random function都有這麼多的學問,長知識了
author | kenchung |
---|---|
permlink | re-oflyhigh-python-cny-20170928t155351637z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 15:53:51 |
last_update | 2017-09-28 15:53:51 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 15:53:51 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 33 |
author_reputation | 41,181,348,504,685 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,194,448 |
net_rshares | 0 |
https://docs.python.org/3.6/library/random.html 补充一下参考信息
author | oflyhigh |
---|---|
permlink | re-oflyhigh-python-cny-20170928t114543127z |
category | cn |
json_metadata | {"tags":["cn"],"links":["https://docs.python.org/3.6/library/random.html"],"app":"steemit/0.1"} |
created | 2017-09-28 11:46:12 |
last_update | 2017-09-28 11:46:12 |
depth | 1 |
children | 1 |
last_payout | 2017-10-05 11:46:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 2.026 HBD |
curator_payout_value | 0.006 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 56 |
author_reputation | 6,269,730,276,883,447 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,174,164 |
net_rshares | 707,426,026,580 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
oflyhigh | 0 | 707,426,026,580 | 30% |
感谢帖子和参考信息。 我是加纳的信息技术学生,学习php。 希望你可以在php上发布一些教程。 我感谢你的帖子。
author | othniel |
---|---|
permlink | re-oflyhigh-re-oflyhigh-python-cny-20170928t131628431z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 13:16:36 |
last_update | 2017-09-28 13:16:36 |
depth | 2 |
children | 0 |
last_payout | 2017-10-05 13:16:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 56 |
author_reputation | 228,170,451,733 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,181,253 |
net_rshares | 0 |
good post :) , i am also python programmer , I'm following. Please follow me.
author | osos |
---|---|
permlink | re-oflyhigh-python-cny-20170928t211930136z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 21:19:39 |
last_update | 2017-09-28 21:19:39 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 21:19:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 80 |
author_reputation | 10,381,606,780 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,218,354 |
net_rshares | 0 |
Very interesting, good post and I like, hopefully the next post better with a more perfect idea. follow me @pojan, Upvote and give a positive comment for me. https://steemit.com/introduceyourself/@pojan/the-next-introduction-for-me-introduceyourself-2017928t182549442z
author | pojan |
---|---|
permlink | re-oflyhigh-python-cny-20170928t124713718z |
category | cn |
json_metadata | {"tags":["cn"],"users":["pojan"],"links":["https://steemit.com/introduceyourself/@pojan/the-next-introduction-for-me-introduceyourself-2017928t182549442z"],"app":"steemit/0.1"} |
created | 2017-09-28 12:47:15 |
last_update | 2017-09-28 12:47:15 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 12:47:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 269 |
author_reputation | 16,348,092,082,289 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,178,777 |
net_rshares | 0 |
感谢分享这个
author | rkkk |
---|---|
permlink | re-oflyhigh-python-cny-20170928t122411068z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 12:24:15 |
last_update | 2017-09-28 12:24:15 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 12:24:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 6 |
author_reputation | 28,219,902,750 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,176,973 |
net_rshares | 0 |
https://steemit.com/rkkk
author | rkkk |
---|---|
permlink | re-oflyhigh-python-cny-20170928t122525949z |
category | cn |
json_metadata | {"tags":["cn"],"links":["https://steemit.com/rkkk"],"app":"steemit/0.1"} |
created | 2017-09-28 12:25:30 |
last_update | 2017-09-28 12:25:30 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 12:25:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 24 |
author_reputation | 28,219,902,750 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,177,071 |
net_rshares | 0 |
https://steemit.com/rkkk
author | rkkk |
---|---|
permlink | re-oflyhigh-python-cny-20170928t122601167z |
category | cn |
json_metadata | {"tags":["cn"],"links":["https://steemit.com/rkkk"],"app":"steemit/0.1"} |
created | 2017-09-28 12:26:03 |
last_update | 2017-09-28 12:26:03 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 12:26:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 24 |
author_reputation | 28,219,902,750 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,177,113 |
net_rshares | 0 |
Thanks for sharing. Good post. :) I'm following. Please follow me...
author | salamsafar |
---|---|
permlink | re-oflyhigh-python-cny-20170928t122206961z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 12:22:06 |
last_update | 2017-09-28 12:22:06 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 12:22:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 68 |
author_reputation | -10,825,830,904 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,176,802 |
net_rshares | 0 |
beautiful language Chinese post
author | shahzadhaneef |
---|---|
permlink | re-oflyhigh-python-cny-20170928t115019762z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 11:50:24 |
last_update | 2017-09-28 11:50:24 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 11:50:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 31 |
author_reputation | 9,381,173,386 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,174,435 |
net_rshares | 0 |
谢谢您!很有意思的文章! 在我们的Tlind软件能找到程序员
author | tlind-org |
---|---|
permlink | re-oflyhigh-python-cny-20170928t223227502z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 22:32:30 |
last_update | 2017-09-28 22:32:30 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 22:32:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 30 |
author_reputation | 2,477,286,111 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,222,548 |
net_rshares | 0 |
具体的没看懂,大体上看懂了。这个语言应该很适合做统计是不是?
author | tvb |
---|---|
permlink | re-oflyhigh-python-cny-20170928t165426401z |
category | cn |
json_metadata | {"tags":["cn"],"app":"steemit/0.1"} |
created | 2017-09-28 16:54:27 |
last_update | 2017-09-28 16:54:27 |
depth | 1 |
children | 0 |
last_payout | 2017-10-05 16:54:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 30 |
author_reputation | 35,098,102,223,749 |
root_title | "Python 随机选取元素的一些方法以及概率问题" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 16,199,438 |
net_rshares | 0 |