[英]PHP Weighted random number
How can I generate a weighted random number between 1 and 10 with 10 being the highest chance and 1 being the lowest chance? 如何生成1到10之间的加权随机数,其中10为最高机会,1为最低机会?
rand(1,10) ?
Needs to be a simple one line code since it will be run 100,000's of times 需要是一个简单的单行代码,因为它将运行100,000次
OK I think I understand what you're trying to say.. 好吧,我想我明白你要说的是什么..
try this : 尝试这个 :
mt_rand(mt_rand(1, 10),10 );
I looped it a million times : 我循环了一百万次:
10 = 292634
9 = 193333
8 = 142815
7 = 109580
6 = 84616
5 = 64498
4 = 47666
3 = 33450
2 = 21286
1 = 10122
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.