I am trying to get random number with beta distribution in PHP 7. I found function stats_rand_gen_beta, but when I was trying to install it by command:
sudo pecl install stats
I obtained the following error
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
pecl/stats requires PHP (version >= 5.3.0, version <= 5.6.99), installed version is 7.0.14-1+deb.sury.org~xenial+1
No valid packages found
install failed
How to handle with this? Is there any replacement for stats
, or other method to simply generate random with given distribution of probability?
I solved this problem checking website https://pecl.php.net/package/stats. There was written, that I should install second version of this package https://pecl.php.net/package/stats/2.0.3
O this blog I found instruction of installation.
Problem is fully solved.
Finally i do not use stats, because I had problem with generating the same number any time.
I found great library:
https://github.com/gburtini/Probability-Distributions-for-PHP
Instalation:
composer require gburtini/distributions
Usage:
require_once "vendor/gburtini/distributions/src/gburtini/Distributions/Beta.php";
$a = 1.1;
$b = 9.3;
$beta = new \gburtini\Distributions\Beta($a, $b);
$res = $beta->rands(20);
var_dump($res);