Giter Site home page Giter Site logo

phanlyhuynh / rando-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hi-folks/rando-php

0.0 1.0 0.0 616 KB

RandoPhp is a open source library that implements random generators (Integer, Byte, Sequences, Boolean) and take random sample from arrays

Home Page: https://packagist.org/packages/hi-folks/rando-php

License: MIT License

PHP 100.00%

rando-php's Introduction

Rando-PHP

CICD Github Actions GitHub last commit GitHub Release Date Packagist PHP Version Support

RandoPHP

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 Char

Sometimes you want to obtain a random char, for example, a numeric char:

Randomize::char()->numeric()->generate();

Or you might want a alphabetic char:

Randomize::char()->alpha()->generate();

You can even do both!

Randomize::char()->alphanumeric()->generate();

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 an Range

Set the range (min and max) Calling range(1,10), it is equivalent of ->min(1)->max(10):

$randomNumber = Randomize::integer()->range(1,10)->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:

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.

rando-php's People

Contributors

roberto-butti avatar septikwar avatar zuruckt avatar anita-ihuman avatar rebelchris avatar davidribeiro avatar webhaikal avatar quanlh-smartosc avatar rocksheep avatar sam0hack avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.