stats_rand_gen_normal

(PECL stats >= 1.0.0)

stats_rand_gen_normalGenerates a single random deviate from a normal distribution with mean, av, and standard deviation, sd (sd >= 0). Method : Renames SNORM from TOMS as slightly modified by BWB to use RANF instead of SUNIF.

설명

float stats_rand_gen_normal ( float $av , float $sd )
Warning

이 함수는 현재 문서화 되어있지 않습니다; 인수 목록만을 제공합니다.

인수

av

sd

반환값

add a note add a note

User Contributed Notes 1 note

up
0
KEINOS
4 years ago
Alternative of "stats_rand_gen_normal()".

<?php
/**
* "Box–Muller transform" based random deviate generator.
*
* @ref https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
*
* @param  float|int $av Average/Mean
* @param  float|int $sd Standard deviation
* @return float
*/
if (! function_exists('stats_rand_gen_normal')) {
    function
stats_rand_gen_normal($av, $sd): float
   
{
       
$x = mt_rand() / mt_getrandmax();
       
$y = mt_rand() / mt_getrandmax();
   
        return
sqrt(-2 * log($x)) * cos(2 * pi() * $y) * $sd + $av;
    }
}
?>
To Top