2017 © Pedro Peláez
 

library distribution

Probability distribution service

image

leaditin/distribution

Probability distribution service

  • Tuesday, July 4, 2017
  • by igorvuckovic
  • Repository
  • 0 Watchers
  • 3 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Leaditin\Distribution

A simple PHP API for distributing values based on their probabilities, (*1)

![Build Status][ico-build] Code Quality Code Coverage Latest Version PDS Skeleton, (*2)

Installation

The preferred method of installation is via Composer. Run the following command to install the latest version of a package and add it to your project's composer.json:, (*3)

composer require leaditin/distribution

Usage

Imagine that you want to simulate creation of 100 users where each must have defined gender. You want to have 53% female and 47% male., (*4)

Imagine that you do not want to generate all female users and after that all male users, instead of that you want these records to be generated randomly., (*5)

This is where Leaditin\Distribution will help you:, (*6)

use Leaditin\Distribution\Collection;
use Leaditin\Distribution\Distributor;
use Leaditin\Distribution\Element;
use Leaditin\Distribution\Exception\DistributorException;

$probabilities = new Collection(
    new Element('MALE', 53),
    new Element('FEMALE', 47)
);

$distributor = new Distributor($probabilities, 100);

# Create user with random gender
$user = new \User();
$user->gender = $distributor->useRandomCode();
$user->save();

# Create user with explicit gender
$user = new \User();
$user->firstName = 'Jon';
$user->lastName = 'Snow';
$user->gender = $distributor->useCode('MALE');
$user->save();

Credits

License

Released under MIT License - see the License File for details., (*7)

The Versions

04/07 2017

dev-master

9999999-dev

Probability distribution service

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Igor Vuckovic

distribution distributor probability leaditin

04/07 2017

1.0.1

1.0.1.0

Probability distribution service

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Igor Vuckovic

distribution distributor probability leaditin