{"id":22344216,"url":"https://github.com/hi-folks/rando-php","last_synced_at":"2025-04-11T23:15:41.052Z","repository":{"id":49056219,"uuid":"280427032","full_name":"Hi-Folks/rando-php","owner":"Hi-Folks","description":"RandoPhp is a open source library that implements random generators (Integer, Char, Byte, Sequences, Boolean) and take random sample from arrays","archived":false,"fork":false,"pushed_at":"2024-11-21T21:01:38.000Z","size":775,"stargazers_count":128,"open_issues_count":0,"forks_count":22,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T23:15:36.719Z","etag":null,"topics":["generator","hacktoberfest","library","package","php","random"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/hi-folks/rando-php","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hi-Folks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-17T13:08:34.000Z","updated_at":"2025-02-23T20:35:30.000Z","dependencies_parsed_at":"2024-12-18T11:00:17.800Z","dependency_job_id":"803f1ada-af5d-4401-897c-c74dc1d50191","html_url":"https://github.com/Hi-Folks/rando-php","commit_stats":{"total_commits":142,"total_committers":20,"mean_commits":7.1,"dds":0.2535211267605634,"last_synced_commit":"5b54cd2782616cfdaa992775513eccc28bea73d0"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hi-Folks%2Frando-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hi-Folks%2Frando-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hi-Folks%2Frando-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hi-Folks%2Frando-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hi-Folks","download_url":"https://codeload.github.com/Hi-Folks/rando-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492883,"owners_count":21113163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["generator","hacktoberfest","library","package","php","random"],"created_at":"2024-12-04T09:09:03.627Z","updated_at":"2025-04-11T23:15:41.025Z","avatar_url":"https://github.com/Hi-Folks.png","language":"PHP","readme":"# Rando-PHP\n\n\n[![Testing RandoPHP](https://img.shields.io/github/actions/workflow/status/hi-folks/rando-php/php.yml?branch=master\u0026label=Test%20RANDO-PHP\u0026style=for-the-badge)](https://github.com/Hi-Folks/rando-php/actions)\n[![GitHub last commit](https://img.shields.io/github/last-commit/hi-folks/rando-php?style=for-the-badge)](https://github.com/Hi-Folks/rando-php/commits/master)\n[![GitHub Release Date](https://img.shields.io/github/release-date/hi-folks/rando-php?style=for-the-badge)](https://github.com/Hi-Folks/rando-php/releases/)\n![Packagist PHP Version Support](https://img.shields.io/packagist/dependency-v/hi-folks/rando-php/php?style=for-the-badge)\n\n![RandoPHP](rando-php.png)\n\nRandoPHP is a PHP open-source package for random stuff. With this package you can:\n- **Draw**: Extract random items (sample) from an array. This is useful when you want to \"draw\" some numbers or items;\n- **Generate**: useful for create random items/sequences:\n   - *item* like integer, byte, boolean, float, lat/long coordinates, char (numeric, alphabetic, alphanumeric);\n   - *sequences* like an array of integers or chars;\n\nWith the fluent interface, you can control some things like:\n- minimum and maximum value you want to create;\n- how many items you want to create;\n- for sequences if you want or not duplicates ([1,5,3,1,1], 1 is duplicate or [1,6,5,3,8], no duplicates);\n- And other stuff, see the documentation for more options.\n\n## Table of contents\n\n- [Installation](#installation)\n- [Usage, how to generate:](#usage)\n  - [Random char](#generate-char)\n  - [Random boolean](#generate-boolean)\n  - [Random float](#generate-a-float)\n  - [Random integer](#generate-an-integer)\n  - [Random Bytes](#generate-bytes)\n  - [Random Date](#generate-a-date)\n  - [Random Sequences](#generate-sequences)\n  - [Random Chars](#random-chars)\n- [Usage, how to extract random values from array/list](#draw-random-stuff)\n\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require hi-folks/rando-php\n```\n\n## Usage\nTo import the right class:\n```php\nuse HiFolks\\RandoPhp\\Randomize;\n```\n\n### Generate Char\n\nSometimes you want to obtain a random char, for example, a numeric char:\n\n```php\nRandomize::char()-\u003enumeric()-\u003egenerate();\n```\nOr you might want an alphabetic char:\n\n```php\nRandomize::char()-\u003ealpha()-\u003egenerate();\n```\n\nYou can even do both!\n```php\nRandomize::char()-\u003ealphanumeric()-\u003egenerate();\n```\n\nYou can generate a lower case char:\n```php\nRandomize::char()-\u003ealpha()-\u003elower()-\u003egenerate();\n```\nYou can generate an upper case char:\n```php\nRandomize::char()-\u003ealpha()-\u003eupper()-\u003egenerate();\n```\n\n\nYou can generate a special character.\nA special character is one of '!\"#$%\u0026'()*+,-./:;\u003c=\u003e?@[\\]^_`{|}~':\n```php\nRandomize::char()-\u003especialCharacters()-\u003egenerate();\n```\n\n### Generate Boolean\n\nSometimes you want to obtain a random boolean `true` or `false` (flip a coin):\n\n``` php\n$randomBool = Randomize::boolean()-\u003egenerate();\n```\n### Generate a Float\n\nSometimes you want to obtain a random float (default min-max range of 0.0 - 1.0). For example, you want to generate a random temperature for a day:\n\n```php\n$randomFloat = Randomize::float()-\u003egenerate();\n```\n\nOr you can set the min-max range of 0 - 90, which is equivalent to -\u003emin(0)-\u003emax(90)\n\n```php\n$randomFloat = Randomize::float()-\u003emin(0)-\u003emax(90)-\u003egenerate();\n```\n\n### Generate an Integer\n\nSometimes you want to obtain a random integer (min-max range). For example, you want to roll the dice:\n\n``` php\n$randomNumber = Randomize::integer()-\u003emin(1)-\u003emax(6)-\u003egenerate();\n```\nThe same thing using `range()` method, instead of `min()` and `max()`:\n\n``` php\n$randomNumber = Randomize::integer()-\u003erange(1,6)-\u003egenerate();\n```\n\nYou can use a shortcut helper to generate an integer calling the constructor with min and max parameters:\n\n``` php\n$randomNumber = Randomize::integer(1,6)-\u003egenerate();\n```\n\n\n### Generate bytes\nSometimes you want to obtain some random bytes (hexadecimal). For example, you want to generate a random RGB color (a hex triplet in hexadecimal format):\n\n```php\n$randomRGB = Randomize::byte()-\u003elength(3)-\u003egenerate();\n```\n\n### Generate a Date\nSometimes you want to obtain a random date. For example, you want to generate a random date:\n\n```php\n$randomDate = Randomize::datetime()-\u003egenerate();\n```\n\nBy default, a date between the first day of the current year to the last day of the current year.\nIf you want to define the range, for example, a range of 01 Jan 2020 to 10 Jan 2020, you can use `min()` and `max()` methods:\n```php\n$randomDate = Randomize::datetime()-\u003emin('2020–01–01')-\u003emax('2020–01–10')-\u003egenerate();\n```\n\nYou can even specify your preferred format for the random date generated, by using the `format()` method:\n```php\n$randomDate = Randomize::datetime()-\u003eformat('d-M-Y')-\u003egenerate();\n```\nYou can use `min()` and `max()` with `format()` method:\n```php\n$randomDate = Randomize::datetime()-\u003emin('2020–01–01')-\u003emax('2020–01–10')-\u003eformat('d-M-Y')-\u003egenerate();\n```\nWith the latest example, you can obtain something like \"05-Jan-2020\".\n\n### Generate sequences\nSometimes, you want to obtain some random sequences. For example, you want to roll the dice 15 times:\n\n```php\n$randomRolls = Randomize::sequence()-\u003emin(1)-\u003emax(6)-\u003ecount(15)-\u003egenerate();\n```\n\nSometimes you want to obtain some random char sequences. For example, char sequences of length 10:\n\n```php\n$randomChars = Randomize::sequence()-\u003echars()-\u003ecount(10)-\u003egenerate();\n```\n\nOr you might want numeric char sequences.\n\n```php\n$randomChars = Randomize::sequence()-\u003echars()-\u003enumeric()-\u003ecount(10)-\u003egenerate();\n```\n\nOr you might want alphabetical char sequences.\n\n```php\n$randomChars = Randomize::sequence()-\u003echars()-\u003ealpha()-\u003ecount(10)-\u003egenerate();\n```\n\nYes, even both.\n\n```php\n$randomChars = Randomize::sequence()-\u003echars()-\u003ealphanumeric()-\u003ecount(10)-\u003egenerate();\n```\n\nYou want 20 lowercase chars:\n```php\nRandomize::sequence()-\u003echars()-\u003ealphaLowerCase()-\u003ecount(20)-\u003easString()-\u003egenerate();\n```\n\nYou want 20 upper case chars:\n```php\nRandomize::sequence()-\u003echars()-\u003ealphaUpperCase()-\u003ecount(20)-\u003easString()-\u003egenerate();\n```\n\n\nSometimes you want to obtain some random sequences with **no duplicates**. For example, you want to play \"Tombola\" (extracting numbers from 1 to 90 with NO duplicates):\n\n```php\n$randomTombola = Randomize::sequence()-\u003emin(1)-\u003emax(90)-\u003ecount(90)-\u003enoDuplicates()-\u003egenerate();\n```\n\nSometimes you want to obtain some random char sequences with **no duplicates**.\n\n```php\n$randomChars = Randomize::sequence()-\u003echars()-\u003ecount(10)-\u003enoDuplicates()-\u003egenerate();\n```\n\nOr you might want numeric char sequences with **no duplicates**. For example, char sequences of length 10:\n\n```php\n$randomChars = Randomize::sequence()-\u003echars()-\u003enumeric()-\u003ecount(10)-\u003enoDuplicates()-\u003egenerate();\n```\n\nOr you might want alphabetical char sequences with **no duplicates**.\n\n```php\n$randomChars = Randomize::sequence()-\u003echars()-\u003ealpha()-\u003ecount(10)-\u003enoDuplicates()-\u003egenerate();\n```\n\nYes, even both and with **no duplicates**.\n\n```php\n$randomChars = Randomize::sequence()-\u003echars()-\u003ealphanumeric()-\u003ecount(10)-\u003enoDuplicates()-\u003egenerate();\n```\n\n### Random String\nIf you want to generate a random string (alphanumeric, only letters, only numbers, with no duplication, lower case, upper case etc) you can use random chars generation.\nTo generate a string use `Randomize::chars()`:\n```php\n$string = Randomize::chars()-\u003egenerate();\n```\nThe default behavior is:\n- 10 chars;\n- only letters (a-z);\n- lowercase;\n- duplication is allowed (the string 'aba' has a duplication for 'a' char).\n\nYou can change the default values with some methods and parameters.\nMethod to set the type of chars (numeric, alpha, alphanumeric...):\n- _alpha()_ : 'a-z', 'A-Z';\n- _alphanumeric()_ : 'a-z', 'A-Z', '0-9';\n- _numeric()_ : '0-9';\n- _alphaLowerCase()_ : 'a-z';\n- _alphaUpperCase()_ : 'A-Z';\n- _specialCharacters()_ : !\"#$%\u0026'()*+,-./:;\u003c=\u003e?@[\\]^_`{|}~\n\nYou have also some methods to \"control\" the output, for example, avoid duplications:\n- `unique()`: it generates a string with at most one occurrence per character.\n\n\n\n#### String with numeric chars ('0'-'9')\nIf you want to generate a string with 16 chars, made with numeric chars ('0'-'9'):\n\n```php\n$string = Randomize::chars(16)-\u003enumeric()-\u003egenerate();\n```\nYou could obtain something like this '3963233500573002'.\n\n#### String with 20 chars, lower case, just letters, no dups\n\nIf you want to obtain a string with 20 chars, lower case and just letters ('a'-'z'), and you want to avoid character duplications ( `alphaLowerCase()` and `unique()` ):\n```php\n$string = Randomize::chars(20)-\u003ealphaLowerCase()-\u003eunique()-\u003egenerate();\n```\nYou could obtain something like this: 'nmbsjhrgdyfxwoltqkzp'.\n#### String with 20 chars, letters and special characters\n\nIf you want to obtain a string with 20 chars, with letters and special characters:\n```php\n$string = Randomize::chars(20)-\u003especialCharacters()-\u003ealpha()-\u003egenerate();\n```\nYou could obtain something like this: 'IOgPckeGGifrD%DRy[*!'.\n\n\n\n### Draw random stuff\nIf you have a list of values and you want to extract/select/draw one or more elements,\nyou could use the `Draw` class instead of `Randomize`.\nFor using the `Draw` class you need to import it:\n```php\nuse HiFolks\\RandoPhp\\Draw;\n```\n\n#### Suggest which programming language you could use in your next project (random)\n```php\nuse HiFolks\\RandoPhp\\Draw;\n\n$randomLanguage = Draw::sample([\"PHP\", \"Python\", \"Golang\", \"Javascript\"])-\u003esnap();\nvar_dump($randomLanguage);\n```\n\n#### Suggest which JS framework you could use in your next project (random)\n```php\n$array=[\"React.js\", \"Vue.js\", \"Svelte.js\", \"Angular.js\" , \"Alpine.js\", \"Vanilla js\"];\n$randomJs = Draw::sample($array)-\u003eextract();\n```\n\n#### Extract 3 JS frameworks you could use in your next project\n```php\n$array=[\"React.js\", \"Vue.js\", \"Svelte.js\", \"Angular.js\" , \"Alpine.js\", \"Vanilla js\"];\n$randomJs = Draw::sample($array)-\u003ecount(3)-\u003eextract();\n```\n\n#### Extract 3 JS frameworks (duplicates allowed)\n```php\n$array = [\"React.js\", \"Vue.js\", \"Svelte.js\", \"Angular.js\", \"Alpine.js\", \"Vanilla js\"];\n$randomJs = Draw::sample($array)-\u003ecount(3)-\u003eallowDuplicates()-\u003eextract();\n```\n\n\n### Testing\n\n``` bash\ncomposer test\n```\n\nIf you want to see some coverage reports you can execute `phpunit` command with `coverage-text` option:\n\n```bash\nvendor/bin/phpunit --coverage-text\n```\n\n### Warning :warning:\n\nUnder the hood, RandoPHP uses some native PHP functions like:\n- array_rand(): [PHP Doc for array_rand](https://www.php.net/manual/en/function.array-rand.php);\n- random_int(): [PHP Doc for random_int](https://www.php.net/manual/en/function.random-int.php);\n- shuffle(): [PHP Doc for shuffle](https://www.php.net/manual/en/function.shuffle);\n- random_bytes(): [PHP Doc for random_bytes](https://www.php.net/manual/en/function.random-bytes).\n\nThese PHP functions use a pseudo-random number generator that is not suitable for cryptographic purposes.\n\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Submit ideas or feature requests or issues\nTake a look if your request is already created https://github.com/Hi-Folks/rando-php/issues\nIf it is not present, you can create a new one https://github.com/Hi-Folks/rando-php/issues/new\n\n## Credits\n\n- [Roberto Butti](https://github.com/roberto-butti)\n- [All Contributors](../../contributors)\n- [PHP Package Boilerplate](https://laravelpackageboilerplate.com)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhi-folks%2Frando-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhi-folks%2Frando-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhi-folks%2Frando-php/lists"}