Rando-PHP
RandoPHP is a PHP open source package for random stuff. With this package you can:
- Draw: Extract random items (sample) from an array. This is useful when you want to "draw" some numbers or items;
- Generate: useful for create random
- item like integer, byte, boolean;
- sequences like array of integer;
With the fluent interface you can control some things like:
- minimum and maximum value for generation;
- how many items you want to create;
- for sequences if you want or not duplicates ([1,5,3,1,1], 1 is duplicate or [1,6,5,3,8], no duplicates);
- And other stuff, see the documentation for more options.
Installation
You can install the package via composer:
composer require hi-folks/rando-php
Usage
Generate Boolean
Sometimes you want to obtain a random boolean true or false.(flip a coin):
$randomBool = Randomize::boolean()->generate();
Generate an Integer
Sometimes you want to obtain a random integer (min - max rang). For example, you want to roll the dice:
$randomNumber = Randomize::integer()->min(1)->max(6)->generate();
Generate bytes
Sometime you want to obtain some random bytes (hexadecimal). For example, you want to generate a random RGB color (a hex triplet in hexadecimal format):
$randomRGB = Randomize::byte()->length(3)->generate();
Generate sequences
Sometime you want to obtain some random sequences. For example, you want to roll the dice 15 times:
$randomRolls = Randomize::sequence()->min(1)->max(6)->count(15)->generate();
Generate sequences with no duplicates
Sometime you want to obtain some random sequences with no duplicates. For example, you want to play "Tombola" (extracting number from 1 to 90 with NO duplicates):
$randomTombola = Randomize::sequence()->min(1)->max(90)->count(90)->noDuplicates()->generate();
Suggest which JS framework you could use in your next project (random)
$array=["React.js", "Vue.js", "Svelte.js", "Angular.js" , "Alpine.js", "Vanilla js"];
$randomJs = Draw::sample($array)->extract();
Extract 3 JS framework you could use in your next project
$array=["React.js", "Vue.js", "Svelte.js", "Angular.js" , "Alpine.js", "Vanilla js"];
$randomJs = Draw::sample($array)->count(3)->extract();
Extract 3 JS framework (duplicates allowed)
$array = ["React.js", "Vue.js", "Svelte.js", "Angular.js", "Alpine.js", "Vanilla js"];
$randomJs = Draw::sample($array)->count(3)->allowDuplicates()->extract();
Testing
composer test
If you want to see some coverage report you can execute phpunit with coverage-text option:
vendor/bin/phpunit --coverage-text
⚠️
Warning Under the hood RandoPHP uses some native PHP functions like:
- array_rand(): PHP Doc for array_rand;
- random_int(): PHP Doc for random_int;
- shuffle(): PHP Doc for shuffle;
- random_bytes(): PHP Doc for random_bytes.
These PHP functions use a pseudo random number generator that is not suitable for cryptographic purposes.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Submit ideas or feature requests or issues
Take a look if your request is already there https://github.com/Hi-Folks/rando-php/issues If it is not present, you can create a new one https://github.com/Hi-Folks/rando-php/issues/new
Credits
License
The MIT License (MIT). Please see License File for more information.