PHP code example of leaditin / distribution

1. Go to this page and download the library: Download leaditin/distribution library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

leaditin / distribution example snippets


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();