{"id":13600663,"url":"https://github.com/awnumar/fastrand","last_synced_at":"2025-10-08T16:33:12.990Z","repository":{"id":57487021,"uuid":"198062865","full_name":"awnumar/fastrand","owner":"awnumar","description":"10x faster than crypto/rand. Uses securely allocated memory. Forked from https://gitlab.com/NebulousLabs/fastrand","archived":false,"fork":false,"pushed_at":"2021-03-15T21:50:12.000Z","size":1355,"stargazers_count":162,"open_issues_count":0,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-27T18:26:57.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/awnumar.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":"2019-07-21T13:56:54.000Z","updated_at":"2024-12-26T15:04:54.000Z","dependencies_parsed_at":"2022-09-01T23:01:17.808Z","dependency_job_id":null,"html_url":"https://github.com/awnumar/fastrand","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awnumar%2Ffastrand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awnumar%2Ffastrand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awnumar%2Ffastrand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awnumar%2Ffastrand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awnumar","download_url":"https://codeload.github.com/awnumar/fastrand/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243846976,"owners_count":20357294,"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-01T18:00:46.052Z","updated_at":"2025-10-08T16:33:12.906Z","avatar_url":"https://github.com/awnumar.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"fastrand\n--------\n\n[![Cirrus CI](https://api.cirrus-ci.com/github/awnumar/fastrand.svg)](https://cirrus-ci.com/github/awnumar/fastrand)\n[![GoDoc](https://godoc.org/github.com/awnumar/fastrand?status.svg)](https://godoc.org/github.com/awnumar/fastrand)\n[![Go Report Card](http://goreportcard.com/badge/github.com/awnumar/fastrand)](https://goreportcard.com/report/github.com/awnumar/fastrand)\n\n```\ngo get github.com/awnumar/fastrand\n```\n\n`fastrand` implements a cryptographically secure pseudorandom number generator. The generator is seeded using the system's default entropy source, and thereafter produces random values via repeated hashing. As a result, `fastrand` can generate randomness much faster than `crypto/rand`, and generation cannot fail beyond a potential panic during `init()`.\n\n`fastrand` was forked from `gitlab.com/NebulousLabs/fastrand`. This version of the package uses securely allocated memory provided by `github.com/awnumar/memguard`.\n\n`fastrand` also scales better than `crypto/rand` and `math/rand` when called in parallel. In fact, `fastrand` can even outperform `math/rand` when using enough threads.\n\nAlternatively, use [`frand`](https://github.com/lukechampine/frand) by [Luke Champine](https://github.com/lukechampine) if you are primarily concerned with speed or if memory security is not part of your threat model. `frand` is [substantially faster](https://github.com/lukechampine/frand#benchmarks) than this package.\n\n## Benchmarks ##\n\n```\n// 32 byte reads\nBenchmarkRead32                     \t10000000\t       175 ns/op\t 181.86 MB/s\nBenchmarkReadCrypto32               \t  500000\t      2733 ns/op\t  11.71 MB/s\n\n// 512 kb reads\nBenchmarkRead512kb                   \t    1000\t   1336217 ns/op\t 383.17 MB/s\nBenchmarkReadCrypto512kb             \t      50\t  33423693 ns/op\t  15.32 MB/s\n\n// 32 byte reads using 4 threads\nBenchmarkRead4Threads32               \t 3000000\t       392 ns/op\t 326.46 MB/s\nBenchmarkReadCrypto4Threads32       \t  200000\t      7579 ns/op\t  16.89 MB/s\n\n// 512 kb reads using 4 threads\nBenchmarkRead4Threads512kb           \t    1000\t   1899048 ns/op\t1078.43 MB/s\nBenchmarkReadCrypto4Threads512kb    \t      20\t  97423380 ns/op\t  21.02 MB/s\n```\n\n## Security ##\n\n`fastrand` uses an algorithm similar to Fortuna, which is the basis for the\n`/dev/random` device in FreeBSD. However, although the techniques used by\n`fastrand` are known to be secure, the specific implementation has not been\nreviewed by a security professional. Use with caution.\n\nThe general strategy is to use `crypto/rand` at init to get 32 bytes of strong\nentropy. From there, the entropy is concatenated to a counter and hashed\nrepeatedly, providing 64 bytes of random output each time the counter is\nincremented. The counter is 16 bytes, which provides strong guarantees that a\ncycle will not be seen throughout the lifetime of the program.\n\nThe `sync/atomic` package is used to ensure that multiple threads calling\n`fastrand` concurrently are always guaranteed to end up with unique counters.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawnumar%2Ffastrand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawnumar%2Ffastrand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawnumar%2Ffastrand/lists"}