{"id":37099963,"url":"https://github.com/aatuh/randutil","last_synced_at":"2026-01-14T12:11:28.177Z","repository":{"id":315108548,"uuid":"1057430755","full_name":"aatuh/randutil","owner":"aatuh","description":"Cryptographically safe random utilities for Go. Helpers for generating random hex strings, tokens, numbers, bytes, UUIDs, emails etc. Thin wrappers around crypto/rand for everyday use.","archived":false,"fork":false,"pushed_at":"2025-10-02T13:05:00.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-02T15:11:49.103Z","etag":null,"topics":["crypto-rand","csprng","developer-experience","faker","go","go-generics","golang","permutation","random","random-stings","randomness","rejection-sampling","rng","sampling","secure-random","shuffle","test-data","uuid","uuidv4","weighted-sampling"],"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/aatuh.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-15T18:02:37.000Z","updated_at":"2025-10-02T13:10:38.000Z","dependencies_parsed_at":"2025-09-16T20:13:55.133Z","dependency_job_id":null,"html_url":"https://github.com/aatuh/randutil","commit_stats":null,"previous_names":["aatuh/randutil"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/aatuh/randutil","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aatuh%2Frandutil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aatuh%2Frandutil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aatuh%2Frandutil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aatuh%2Frandutil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aatuh","download_url":"https://codeload.github.com/aatuh/randutil/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aatuh%2Frandutil/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-rand","csprng","developer-experience","faker","go","go-generics","golang","permutation","random","random-stings","randomness","rejection-sampling","rng","sampling","secure-random","shuffle","test-data","uuid","uuidv4","weighted-sampling"],"created_at":"2026-01-14T12:11:27.314Z","updated_at":"2026-01-14T12:11:28.090Z","avatar_url":"https://github.com/aatuh.png","language":"Go","readme":"# randutil\n\nCSPRNG-first random utilities for Go. One small package that does the\ncommon random things: bias-free integers, bytes, strings/tokens, emails,\nshuffle/sample for slices, and realistic date/time helpers.\n\n## Install\n\n```bash\ngo get github.com/aatuh/randutil/v2\n```\n\n## Quick start\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n\n  \"github.com/aatuh/randutil/v2/numeric\"\n  \"github.com/aatuh/randutil/v2/collection\"\n  \"github.com/aatuh/randutil/v2/randstring\"\n  \"github.com/aatuh/randutil/v2/email\"\n  \"github.com/aatuh/randutil/v2/randtime\"\n  \"github.com/aatuh/randutil/v2/uuid\"\n)\n\nfunc main() {\n  // Numbers\n  n := numeric.MustIntRange(10, 20)     // inclusive\n  f := numeric.MustFloat64()            // [0,1)\n  b := numeric.MustBytes(16)            // 16 random bytes\n  ok := numeric.MustBool()\n\n  // Strings / tokens\n  s   := randstring.MustString(12)                  // lower-case alnum\n  hex := randstring.MustHex(32)                     // 32 hex chars (16 bytes)\n  b64 := randstring.MustBase64(24)                  // encodes 24 random bytes\n  tok := randstring.MustTokenURLSafe(24)            // URL-safe base64\n  \n  // Email addresses\n  mail := email.MustEmailSimple(16)                 // exact-length local@domain.com\n  mail2 := email.MustEmail(email.EmailOptions{TLD: \"org\"}) // options\n\n  // Collections\n  arr := []int{1,2,3,4,5}\n  collection.MustShuffle(arr)                       // in-place Fisher–Yates\n  top2 := collection.MustSample(arr, 2)             // k without replacement\n  pick := collection.MustSlicePickOne(arr)\n  pickedMany := collection.MustPickByProbability([]string{\"a\",\"b\",\"c\"}, 0.5)\n\n  // Time\n  t  := randtime.MustDatetime()\n  p  := randtime.MustTimeInNearPast()\n  fu := randtime.MustTimeInNearFuture()\n\n  // UUIDs\n  u4 := uuid.MustV4()\n  u7 := uuid.MustV7()\n\n  fmt.Println(n, f, len(b), ok, s, hex, b64, tok, mail, mail2, arr, top2, pick, pickedMany, t, p, fu, u4, u7)\n}\n```\n\nNote: Every `MustX(...)` has a non-panicking `X(...)` variant that returns\n`(T, error)` for use in servers/CLIs where you want to handle errors.\n\n## API overview\n\n### Numbers\n\nUniform integers without modulo bias (rejection sampling under the hood),\n`[0,1)` float64, and byte helpers. Range functions are inclusive.\n\n* `Uint64()`\n* `Uint64n(n uint64)` → \\[0,n)\n* `Intn(n int)`, `Int64n(n int64)` → \\[0,n)\n* `IntRange(min, max)`, `Int32Range`, `Int64Range` (inclusive)\n* `AnyInt*`, `Positive*`, `Negative*`\n* `Float64()`\n* `Bytes(n)`, `Fill(b)`\n\n### Booleans\n\n* `Bool()` / `MustBool()`\n\n### Strings \u0026 tokens\n\nLower-case alnum by default; hex/base64 helpers.\n\n* `String(n)` and `StringWithCharset(n, charset)`\n* `Hex(len)` where `len` must be even (2 chars per byte)\n* `Base64(byteLen)`, `TokenHex(byteLen)`, `TokenBase64(byteLen)`,\n  `TokenURLSafe(byteLen)`\n\n### Email addresses\n\nRandom email generation with customizable local parts, domains, and TLDs.\n\n* `Email(opts)` - Full control with EmailOptions\n* `EmailSimple(totalLength)` - Legacy exact-length emails\n* `EmailWithCustomLocal(localPart)`\n* `EmailWithCustomDomain(domainPart)`\n* `EmailWithCustomTLD(tld)`\n* `EmailWithRandomTLD()`\n* `EmailWithoutTLD()`\n\n### Collections (slices)\n\nUnbiased Fisher–Yates shuffle, sampling without replacement, and simple picks.\n\n* `Shuffle[T]([]T)`\n* `Sample[T]([]T, k)` – returns a new slice, no duplicates\n* `Perm(n)` – random permutation of 0..n-1\n* `SlicePickOne[T]([]T)`\n* `PickByProbability[T]([]T, p float64)` – picks each item with prob `p`\n  (`SlicePickMany` with 0..100 threshold remains for legacy use)\n\n### Time\n\nCalendar-correct random datetimes and near-past/future helpers.\n\n* `Datetime()` → between years 1..9999 (UTC), month/day validity handled\n* `TimeInNearPast()` / `TimeInNearFuture()` → a few minutes around now\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faatuh%2Frandutil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faatuh%2Frandutil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faatuh%2Frandutil/lists"}