Introduction
, (*1)
Generate a number or a list of numbers between a given minimum and maximum.
The default implementation is based on the
CSPRNG
implementation introduced in PHP 7., (*2)
Installation
composer require hylianshield/number-generator:^1.0
Usage
<?php
use HylianShield\NumberGenerator\NumberGenerator;
$generator = new NumberGenerator();
$generator->generateNumber(); // Number between 0 and PHP_INT_MAX
$generator->generateNumber(12); // Number between 12 and PHP_INT_MAX
$generator->generateNumber(42, 1337); // Number between 42 and 1337
// List of 10 numbers between 42 and 1337.
$numbers = iterator_to_array(
$generator->generateList(10, 42, 1337)
);
To generate an example, try running:, (*3)
composer example 10 42 1337
Output will be similar to:, (*4)
> ./examples/basic-range.php '10' '42' '1337'
685
993
472
977
876
997
459
281
529
1287