Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: stats_rand_gen_normal - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: stats_rand_gen_normal

2025-05-13

stats_rand_gen_normal

(PECL stats >= 1.0.0)

stats_rand_gen_normalGenerates a single random deviate from a normal distribution

说明

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

Returns a random deviate from the normal distribution with mean, av, and standard deviation, sd.

参数

av

The mean of the normal distribution

sd

The standard deviation of the normal distribution

返回值

A random deviate

添加备注

用户贡献的备注 1 note

up
4
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;
}
}
?>

官方地址:https://www.php.net/manual/en/function.stats-rand-gen-normal.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3