{"id":13622847,"url":"https://github.com/ircmaxell/RandomLib","last_synced_at":"2025-04-15T10:31:46.049Z","repository":{"id":6932830,"uuid":"8184122","full_name":"ircmaxell/RandomLib","owner":"ircmaxell","description":"A library for generating random numbers and strings","archived":false,"fork":false,"pushed_at":"2018-09-06T13:12:34.000Z","size":161,"stargazers_count":843,"open_issues_count":23,"forks_count":115,"subscribers_count":37,"default_branch":"master","last_synced_at":"2024-11-07T02:06:20.483Z","etag":null,"topics":[],"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/ircmaxell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-13T17:39:47.000Z","updated_at":"2024-10-31T07:54:30.000Z","dependencies_parsed_at":"2022-09-13T11:23:29.328Z","dependency_job_id":null,"html_url":"https://github.com/ircmaxell/RandomLib","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2FRandomLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2FRandomLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2FRandomLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2FRandomLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ircmaxell","download_url":"https://codeload.github.com/ircmaxell/RandomLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223668469,"owners_count":17182933,"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":[],"created_at":"2024-08-01T21:01:24.930Z","updated_at":"2024-11-08T10:31:12.968Z","avatar_url":"https://github.com/ircmaxell.png","language":"PHP","readme":"RandomLib\n=========\n\n[![Build Status](https://travis-ci.org/ircmaxell/RandomLib.svg?branch=master)](https://travis-ci.org/ircmaxell/RandomLib)\n\nA library for generating random numbers and strings of various strengths.\n\nThis library is useful in security contexts.\n\nInstall\n-------\n\nVia Composer\n\n```sh\n$ composer require ircmaxell/random-lib\n```\n\nUsage\n-----\n\n### Factory\n\nA factory is used to get generators of varying strength:\n\n```php\n$factory = new RandomLib\\Factory;\n$generator = $factory-\u003egetGenerator(new SecurityLib\\Strength(SecurityLib\\Strength::MEDIUM));\n```\n\nA factory can be configured with additional mixers and sources but can be\nused out of the box to create both medium and low strength generators.\n\nConvenience methods are provided for creating high, medium, and low\nstrength generators. Example:\n\n```php\n$generator = $factory-\u003egetMediumStrengthGenerator();\n```\n\n#### $factory-\u003egetLowStrengthGenerator()\n\nConvenience method to get a low strength random number generator.\n\nLow Strength should be used anywhere that random strings are needed in a\nnon-cryptographical setting.  They are not strong enough to be used as\nkeys or salts.  They are however useful for one-time use tokens.\n\n\n#### $factory-\u003egetMediumStrengthGenerator()\n\nConvenience method to get a medium strength random number generator.\n\nMedium Strength should be used for most needs of a cryptographic nature.\nThey are strong enough to be used as keys and salts.  However, they do\ntake some time and resources to generate, so they should not be over-used\n\n\n#### $factory-\u003egetHighStrengthGenerator()\n\nConvenience method to get a high strength random number generator.\n\nHigh Strength keys should ONLY be used for generating extremely strong\ncryptographic keys.  Generating them is very resource intensive and may\ntake several minutes or more depending on the requested size.\n\n**There are currently no mixers shipped with this package that are\ncapable of creating a high space generator. This will not work out of\nthe box!**\n\n\n### Generator\n\nA generator is used to generate random numbers and strings.\n\nExample:\n\n```php\n// Generate a random string that is 32 bytes in length.\n$bytes = $generator-\u003egenerate(32);\n\n// Generate a whole number between 5 and 15.\n$randomInt = $generator-\u003egenerateInt(5, 15);\n\n// Generate a 32 character string that only contains the letters\n// 'a', 'b', 'c', 'd', 'e', and 'f'.\n$randomString = $generator-\u003egenerateString(32, 'abcdef');\n```\n\n#### $generator-\u003egenerate($size)\n\nGenerate a random byte string of the requested size.\n\n\n#### $generator-\u003egenerateInt($min = 0, $max = PHP_INT_MAX)\n\nGenerate a random integer with the given range. If range (`$max - $min`)\nis zero, `$max` will be used.\n\n\n#### $generator-\u003egenerateString($length, $characters = '')\n\nGenerate a random string of specified length.\n\nThis uses the supplied character list for generating the new result\nstring. The list of characters should be specified as a string containing\neach allowed character.\n\nIf no character list is specified, the following list of characters is used:\n\n    0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/\n\n**Examples:**\n\n```php\n// Give the character list 'abcdef':\nprint $generator-\u003egenerateString(32, 'abcdef').\"\\n\";\n\n// One would expect to receive output that only contained those\n// characters:\n//\n// adaeabecfbddcdaeedaedfbbcdccccfe\n// adfbfdbfddadbfcbbefebcacbefafffa\n// ceeadbcabecbccacdcaabbdccfadbafe\n// abadcffabdcacdbcbafcaecabafcdbbf\n// dbdbddacdeaceabfaefcbfafebcacdca\n```\n\nLicense\n-------\n\nMIT, see LICENSE.\n\n\nCommunity\n---------\n\nIf you have questions or want to help out, join us in the **#php.security**\nchannel on **irc.freenode.net**.\n\nSecurity Vulnerabilities\n========================\n\nIf you have found a security issue, please contact the author directly at [me@ircmaxell.com](mailto:me@ircmaxell.com).\n","funding_links":[],"categories":["安全","Table of Contents","目录","安全 Security","PHP","Security","安全( Security )"],"sub_categories":["Security","安全 Security"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fircmaxell%2FRandomLib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fircmaxell%2FRandomLib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fircmaxell%2FRandomLib/lists"}