PHP code example of outcloud / geometric-array-random

1. Go to this page and download the library: Download outcloud/geometric-array-random 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/ */

    

outcloud / geometric-array-random example snippets


$matrix = [
    [1, 0.1], // value, probablility
    [2, 0.1],
    [3, 0.1],
    [4, 0.3],
    [5, 0.2],
    [null, 0.2],
]; 

$generator = new GeometricArrayRandom($matrix);
$result = $generator->nextNValues(10);  // possible result: [4, null, 5, 1, null, 5, 5, 4, null, 4]
$singleValue = $generator->nextValue(); // possible result : 4

$matrix = [
    [1, 2, 3, 4, 5, null], // values
    [0.1, 0.1, 0.1, 0.3, 0.2, 0.2] // probabilities
]; 

$generator = new GeometricArrayRandom($matrix, GeometricArrayRandom::MODE_TWO_DIMENSIONS);
$result = $generator->nextNValues(10);  // possible result: [4, null, 5, 1, null, 5, 5, 4, null, 4]
$singleValue = $generator->nextValue(); // possible result : 4