0
定的重量我有這個useragents'陣列PHP的隨機與數組
$userAgents = array ('Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1', //FF4
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120427 Firefox/15.0a1', //F15
'Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00', //O10
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10', //S5
'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1)', //IE7
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1)' //IE8
'Mozilla/5.0 (MSIE 9.0; Windows NT 6.1; Trident/5.0)' //IE9
);
我想獲得隨機不同的用戶代理,所以我用:
$userAgent = $userAgents[array_rand($userAgents)];
我該怎麼辦了相同的隨機選擇,但給予更多的權重,比方說,3個第一個數組條目......?
http://stackoverflow.com/questions/445235/generating-random-results-by-weight- in-php – kevinamadeus
@kevinamadeus感謝Kevinamadeus提供的鏈接,但正如你所看到的那樣,第一個'naif'建議不是解決方案,其他答案包括浮點數組的總和和計算。我試圖做隨機的字符串.. – Alucard