handybitesize/distributed-random 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

handybitesize/distributed-random

Composer 安装命令:

composer require handybitesize/distributed-random

包简介

Generate random numbers from a range with a normal distribution. Allows skewing and rounding.

README 文档

README

Normally distributed random values for PHP

DistributedRandom allows you generate random values within a range enforcing normal distribution rahter than the uniform distribution rand() et al will give you.

Disclaimer. This may not be real math(s). I use it when generating random objects for testing. For example if I want to generate 2000 users in one of 4 user permission groups, if I randomise the user permission_group_id I can expected roughly 500 users in each. However I usually want the majority of generated users to be in the less permissive groups and only a few "admins" created. This library lets you do that by randomisng with a large skew towards the lower end.

You can see the sort of distributions in the demo script

php -S localhost:8080 demo/web.php 

Setup

Add the library to your composer.json file in your project:

{
  "require": {
      "handybitesize/distributed-random": "0.*"
  }
}

Use composer to install the library:

$ php composer.phar install

Composer will install DistributedRandom inside your vendor folder. Then you can add the following to your .php files to use the library with Autoloading.

require_once(__DIR__ . '/vendor/autoload.php');

Alternatively, use composer on the command line to require and install DistributedRandom:

$ php composer.phar require handybitesize/distributed-random:0.*

Minimum Requirements

  • PHP 5.3

Usage

use HandyBiteSize\DistributedRandom\GenerateRandom;

//examples here


$randomise = new GenerateRandom();

//random double between 0 and 1 distributed around 0.5
$rand = $randomise->random();

//Array of 10 randon doubles between 0 and 1 distributed around 0.5
$rand = $randomise->randomArray(10);

//eg
//[0.50398172239527, 0.55248558880547, 0.25614964553752, 0.80148380196869, 0.58439718574973,
// 0.48014020914308, 0.73432188492932, 0.58615275804089, 0.34302056021055, 0.41324347746747]



//random double between 10 and 100 distributed around 10 and rounded to nearest 10
$rand = $randomise->random(10, 100, 10, 10);

// array of 10 as above
$rand = $randomise->randomArray(10, 10, 100, 10, 10);

// eg
// [10, 30, 20, 20, 20, 10, 10, 50, 20, 20]

Unit Tests

To follow!

$ cd tests
$ phpunit

License

Licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固