{"id":15525160,"url":"https://github.com/antonioribeiro/random","last_synced_at":"2025-04-09T09:06:15.798Z","repository":{"id":57044209,"uuid":"103996703","full_name":"antonioribeiro/random","owner":"antonioribeiro","description":"Generate random strings or numeric values","archived":false,"fork":false,"pushed_at":"2017-12-18T22:17:43.000Z","size":31,"stargazers_count":71,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T06:08:48.805Z","etag":null,"topics":["faker","numbers","patterns","php","random","strings"],"latest_commit_sha":null,"homepage":null,"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/antonioribeiro.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}},"created_at":"2017-09-18T22:04:51.000Z","updated_at":"2024-01-28T06:10:53.000Z","dependencies_parsed_at":"2022-08-24T01:21:09.273Z","dependency_job_id":null,"html_url":"https://github.com/antonioribeiro/random","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Frandom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Frandom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Frandom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonioribeiro%2Frandom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonioribeiro","download_url":"https://codeload.github.com/antonioribeiro/random/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008629,"owners_count":21032556,"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":["faker","numbers","patterns","php","random","strings"],"created_at":"2024-10-02T10:55:14.684Z","updated_at":"2025-04-09T09:06:15.779Z","avatar_url":"https://github.com/antonioribeiro.png","language":"PHP","readme":"# Random\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/pragmarx/random.svg?style=flat-square\u0026update=123)](https://packagist.org/packages/pragmarx/random)\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status](https://img.shields.io/scrutinizer/build/g/antonioribeiro/random.svg?style=flat-square)](https://scrutinizer-ci.com/g/antonioribeiro/random/build-status/master)\n[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/antonioribeiro/random.svg?style=flat-square)](https://scrutinizer-ci.com/g/antonioribeiro/random/?branch=master)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/antonioribeiro/random.svg?style=flat-square)](https://scrutinizer-ci.com/g/antonioribeiro/random/?branch=master)\n[![StyleCI](https://styleci.io/repos/103568219/shield)](https://styleci.io/repos/103996703)\n\n#### Generate random strings, numbers, bytes, patterns, and a lot more\n\n## Features\n\nIt generates cryptographically secure **pseudo-random** bytes (using `random_bytes()` and `random_int()`) to make:\n\n- Strings\n- Numbers (strings or integers)\n- Upper, lower and mixed case\n- Prefixed and suffixed random strings\n- Hexadecimal\n- Regex patterns ([abcd], [aeiou], [A-Z0123], [0-9a-f])\n- Raw strings, giving you whatever `random_bytes()` generates\n\n#### Faker\n\nIf you have [Faker](https://github.com/fzaninotto/Faker) installed it falls back to it, giving you access to random names, dates, cities, phones, and a lot more.\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require pragmarx/random\n```\n\n## Usage\n\n#### Basic array usage\n\n``` php\n$this-\u003erandom = new PragmaRX\\Random\\Random();\n\n$this-\u003erandom-\u003eget(); /// will generate an alpha string which is the same of\n\n$this-\u003erandom-\u003ealpha()-\u003eget();\n```\n\nShould give you 16 chars (default size) string \n\n``` text\n   Ajv3ejknLmqwC36z\n```\n\n#### Defining the size\n\n``` php\n$this-\u003erandom-\u003esize(32)-\u003eget();\n```\n\n#### Upper and lower case\n\n``` php\n$this-\u003erandom-\u003euppercase()-\u003eget();\n$this-\u003erandom-\u003elowercase()-\u003esize(255)-\u003eget();\n```\n\nTo get back to mixed case you can just:\n\n``` php\n$this-\u003erandom-\u003emixedcase()-\u003eget();\n```\n\n#### Defining a pattern\n\nThe pattern method uses regex, so you can:\n\n``` php\n$this-\u003erandom-\u003epattern('[abcd]')-\u003eget();\n\n$this-\u003erandom-\u003epattern('[A-F0-9]')-\u003eget(); /// Hexadecimal\n```\n\nTo get\n\n``` text\n   abcddcbabbacbbdabbcb\n```\n\n#### Numeric and Integer \n\nThe pattern method uses regex, so you can:\n\n``` php\n$this-\u003erandom-\u003enumeric()-\u003estart(10)-\u003eend(20)-\u003eget();\n```\n\nTo get\n\n``` text\n   (int) 18\n```\n\nBut if you set the size \n\n``` php\n$this-\u003erandom-\u003enumeric()-\u003esize(3)-\u003eget();\n```\n\nYou'll get a string\n\n``` text\n   (string) 123\n```\n\n#### Hexadecimal \n\n``` php\n$this-\u003erandom-\u003ehex()-\u003esize(10)-\u003eget();\n```\n\nHexadecimal is uppercase by default, but you can get a lowercase by doing:\n\n``` php\n$this-\u003erandom-\u003ehex()-\u003elowercase()-\u003eget();\n```\n\n#### Prefix \u0026\u0026 Suffix \n\n``` php\n$this-\u003erandom-\u003ehex()-\u003eprefix('#')-\u003esize(6)-\u003elowercase()-\u003eget();\n```\n\nAnd you should get a random CSS color: \n\n``` text\n#fafafa\n```\n\nOf course, the same works for suffixes \n\n``` php\n$this-\u003erandom-\u003eprefix('!')-\u003esuffix('@')-\u003eget();\n```\n\n#### Trivia\n\nThere are currently 43982 questions in the trivia database, and this is how you get them:\n\n``` php\n$this-\u003erandom-\u003etrivia()-\u003eget();\n\n$this-\u003erandom-\u003etrivia()-\u003ecount(2)-\u003eget();\n```\n\nYou'll need to install the Trivia database package:\n\n``` bash\n$ composer require pragmarx/trivia\n```\n\n#### Faker\n\nIf you install Faker\n\n``` bash\ncomposer require fzaninotto/faker\n```\n   \nYou'll also have access to all of the Faker features, like:\n   \n``` php\n$this-\u003erandom-\u003ecity()-\u003eget();\n```\n\nAnd also use all other features of Random\n   \n``` php\n$this-\u003erandom-\u003eprefix('city: ')-\u003ecity()-\u003elowercase()-\u003eget();\n```\n\nYou can also change the faker class, you another one pleases you more:\n\n``` php\n$this-\u003erandom-\u003efakerClass(AnotherFaker\\Factory::class)-\u003edate()-\u003eget();\n```\n\n#### Raw strings\n\nUsually the package returns characters in the range of Base64 (A to Z, a to z and 0 to 9), but you can completely disable this feature and make it return whatever `random_bytes()` generates: \n\n``` php\n$this-\u003erandom-\u003eraw()-\u003eget();\n```\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Testing\n\n``` bash\n$ composer update\n$ vendor/bin/phpunit\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email acr@antoniocarlosribeiro.com instead of using the issue tracker.\n\n## Credits\n\n- [Antonio Carlos Ribeiro][link-author]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n\n[ico-version]: https://img.shields.io/packagist/v/pragmarx/recovery.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/pragmarx/recovery/master.svg?style=flat-square\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/pragmarx/recovery.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/pragmarx/recovery.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/pragmarx/recovery.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/pragmarx/recovery\n[link-travis]: https://travis-ci.org/pragmarx/recovery\n[link-scrutinizer]: https://scrutinizer-ci.com/g/pragmarx/recovery/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/pragmarx/recovery\n[link-downloads]: https://packagist.org/packages/pragmarx/recovery\n[link-author]: https://github.com/antonioribeiro\n[link-contributors]: ../../contributors\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonioribeiro%2Frandom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonioribeiro%2Frandom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonioribeiro%2Frandom/lists"}