2016-03-25 114 views
0

在Python 5中是否有幾何隨機數生成器可用,如numpy.random.geometric在python中?我試圖找到PHP的統計信息庫,stats_rand_gen_exponential是我能找到的最接近的函數。還是有更快更好的方法來從我們已有的可用的PHP中生成幾何隨機數字?生成幾何隨機數

+0

是的,有。嘗試使用http://www.nusphere.com/kb/phpmanual/function.stats-rand-gen-exponential.htm – Justinas

+0

這是指數正確的,我需要幾何。 – Wajahat

回答

0

我發現了一個數學方法來從一個統一的隨機數生成幾何隨機數here

使用此方法,以下代碼將生成一個幾何隨機變量,其中p = 0.1

$p=0.1; 
$geo_rand=floor(log(rand01())/log(1-$p); 

function rand01() 
{ // auxiliary function 
    // returns random number with flat distribution from 0 to 1 
     return (float)rand()/(float)getrandmax(); 
}