承接 qmegas/php-rand-custom-distribution 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

qmegas/php-rand-custom-distribution

Composer 安装命令:

composer require qmegas/php-rand-custom-distribution

包简介

Random number generator with custom distribution

README 文档

README

Standard PHP functions like rand or mt_rand generate random numbers with normal distribution, however sometimes it required to generate random numbers with different distribution, for example binomial distribution.

Installation

composer require qmegas/php-rand-custom-distribution

Requirements

PHP >= 7.0

Simple Example

$generator = new \Qmegas\RandomGenerator(50, 150, function(float $i) {
	return $i * 100;
});
echo $generator->getNumber();

Class constractor receives 3 arguments: low-high bounds of generated numbers and distribution function. Distribution function receives float argument between 0 and 1 and should return some integer value >= 0, see additional examples for better understanding.

Some Additional Examples

Normal Distribution
$generator = new \Qmegas\RandomGenerator($min, $max, function() {
	return 1;
});
$generator = new \Qmegas\RandomGenerator($min, $max, function(float $i) {
	return $i * 100;
});
$generator = new \Qmegas\RandomGenerator($min, $max, function(float $i) {
	return (1 - $i) * 100;
});
$generator = new \Qmegas\RandomGenerator($min, $max, function(float $i) {
	return (1 - $i) * 200 * $i;
});
$generator = new \Qmegas\RandomGenerator($min, $max, function(float $i) {
	return (2 * (1 - $i) * ($i ** 0.5) + ($i ** 2)) * 100;
});
$generator = new \Qmegas\RandomGenerator($min, $max, function(float $i) {
	return ($i ** 3) * 100;
});
$generator = new \Qmegas\RandomGenerator($min, $max, function(float $i) {
	return (3 * ((1 - $i) ** 2) * $i + ($i ** 3)) * 100;
});
$generator = new \Qmegas\RandomGenerator($min, $max, function(float $i) {
	return (1 / (1 + exp(-10 * ($i - 0.5)))) * 100;
});

统计信息

  • 总下载量: 79
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-02