{"id":19078215,"url":"https://github.com/mazen160/go-random","last_synced_at":"2025-04-30T04:41:43.233Z","repository":{"id":41877262,"uuid":"344722188","full_name":"mazen160/go-random","owner":"mazen160","description":"🌐 go-random: A fast, clear, and cryptographically-secure random data generator for Golang","archived":false,"fork":false,"pushed_at":"2021-03-08T10:26:41.000Z","size":6,"stargazers_count":30,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-30T04:41:41.135Z","etag":null,"topics":["crypto","cryptography","go","golang","golang-library","golang-package","random","random-generation"],"latest_commit_sha":null,"homepage":"","language":"Go","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/mazen160.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-05T06:54:54.000Z","updated_at":"2024-11-23T02:45:02.000Z","dependencies_parsed_at":"2022-09-15T21:23:02.579Z","dependency_job_id":null,"html_url":"https://github.com/mazen160/go-random","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazen160%2Fgo-random","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazen160%2Fgo-random/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazen160%2Fgo-random/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazen160%2Fgo-random/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mazen160","download_url":"https://codeload.github.com/mazen160/go-random/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251644826,"owners_count":21620630,"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":["crypto","cryptography","go","golang","golang-library","golang-package","random","random-generation"],"created_at":"2024-11-09T02:07:20.303Z","updated_at":"2025-04-30T04:41:43.210Z","avatar_url":"https://github.com/mazen160.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-random\n\n## A fast, clear, and cryptographically-secure random data generator for Golang\n\ngo-random is a fast, clear, and cryptographically-secure random data generator for Golang. It was developed out of the frustration on finding simple ways to write random string and data generator in Golang without having to write complex functions every time.\n\nWhy? Security should be baked-in within frameworks for developers. Security should be the easy option.\n\ngo-random uses the standard Golang APIs to generate randomness (crypto/rand), with an abstracted API that is clear to use.\n\n# Features\n\n- Clear and simple API\n- Extremely fast\n- Cryptographically-secure (based on crypto/rand) Golang APIs\n- Concurrency-safe: You can run millions of go-routines and not have a token collision as the randomness seed is different for each call.\n\n# Use-cases for go-random?\n\nYou can use go-random for secure-by-default password and token generation for your application.\n\n# Installation\n\n```shell\ngo get -u github.com/mazen160/go-random\n```\n\n# Usage\n\n## Generating Random String\n\nA secure string (token) with the length of 32 characters.\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/mazen160/go-random\"\n)\n\nfunc main() {\n\tdata, err := random.String(32)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(data)\n}\n```\n\nOutput:\n\n```\n\u003e G83zSBEbKeCiV3ij0WcuqR0lIZRJMMc2\n```\n\n## Generating Random Bytes\n\nRandom bytes with the length of 32 bytes.\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/mazen160/go-random\"\n)\n\nfunc main() {\n\tdata, err := random.Bytes(32)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(data)\n}\n\n```\n\nOutput:\n\n```\n\u003e [57 63 142 3 148 39 175 87 69 12 178 46 138 42 11 175 93 13 142 0 97 231 132 200 151 143 241 82 235 167 34 33]\n```\n\n## Generating Random Integer\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/mazen160/go-random\"\n)\n\nfunc main() {\n\tdata, err := random.GetInt(1024)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(data)\n}\n```\n\nOutput:\n\n```\n\u003e 981\n```\n\n## Finding a random integer between 50 to 2000.\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/mazen160/go-random\"\n)\n\nfunc main() {\n\tdata, err := random.IntRange(50, 2500)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tfmt.Println(data)\n}\n```\n\nOutput:\n\n```\n\u003e 1527\n```\n\n## Selecting a random set of characters from a given character set (charset)\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/mazen160/go-random\"\n)\n\nfunc main() {\n\tcharset := \"abcde01235\"\n\tlength := 20\n\tdata, err := random.Random(length, charset, true)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\n\tfmt.Println(data)\n}\n```\n\nOutput:\n\n```\n\u003e 0ee130e152dce0bb5123\n```\n\n## Select a random string from a slice of strings\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/mazen160/go-random\"\n)\n\nfunc main() {\n\ts := []string{\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"}\n\tdata, err := random.Choice(s)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\n\tfmt.Println(data)\n}\n```\n\nOutput:\n\n```\n\u003e d\n```\n\n### Use Pre-defined Charsets\n\ngo-random has a pre-defined charset:\n\n* `Digits` Digits: `[0-9]`\n* `ASCIILettersLowercase`: Asci Lowercase Letters: `[a-z]`\n* `ASCIILettersUppercase`: Ascii Uppercase Letters: `[A-Z]`\n* `Letters`: Ascii Letters: `[a-zA-Z]`\n* `ASCIICharacters`: Ascii Charaters: `[a-zA-Z0-9]`\n* `Hexdigits`: Hex Digits: `[0-9a-fA-F]`\n* `Octdigits`: Octal Digits: `[0-7]`\n* `Punctuation`: Punctuation and special characters.\n* `Printables`: All printables.\n\nTo use, you can access it as: `random.Letters`.\n\n# Contribution\n\nContributions are more than welcome. Please share your ideas by Github issues and pull requests.\n\n### Wishlist\n\n- Gopher Logo 🙏\n- Reviews and thoughts on changes and improvements?\n\n# License\n\nThe project is licensed under MIT license.\n\n\n## Author\n*Mazin Ahmed*\n* Website: [https://mazinahmed.net](https://mazinahmed.net)\n* Email: mazin [at] mazinahmed [dot] net\n* Twitter: [https://twitter.com/mazen160](https://twitter.com/mazen160)\n* Linkedin: [http://linkedin.com/in/infosecmazinahmed](http://linkedin.com/in/infosecmazinahmed)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazen160%2Fgo-random","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmazen160%2Fgo-random","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazen160%2Fgo-random/lists"}