{"id":16874523,"url":"https://github.com/joway/fastrand","last_synced_at":"2025-04-11T11:25:27.303Z","repository":{"id":57635110,"uuid":"322261966","full_name":"joway/fastrand","owner":"joway","description":null,"archived":false,"fork":false,"pushed_at":"2020-12-17T14:02:19.000Z","size":4,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T07:51:09.424Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-17T10:38:06.000Z","updated_at":"2024-03-30T06:08:31.000Z","dependencies_parsed_at":"2022-09-26T20:21:17.183Z","dependency_job_id":null,"html_url":"https://github.com/joway/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/joway%2Ffastrand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joway%2Ffastrand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joway%2Ffastrand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joway%2Ffastrand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joway","download_url":"https://codeload.github.com/joway/fastrand/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248382848,"owners_count":21094563,"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-10-13T15:33:09.382Z","updated_at":"2025-04-11T11:25:27.281Z","avatar_url":"https://github.com/joway.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastrand\n\n## Background\n\nGolang using a single [globalRand](https://github.com/golang/go/blob/master/src/math/rand/rand.go#L293) object between\nmultiple goroutines, which creates [race conditions](https://github.com/golang/go/issues/20387). And the exported method `rand.NewSource()` just creates a\nnon-thread-safe [rngSource]() object.\n\nFastrand wrap the internal `rngSource` struct into `sync.Pool`, and make it could run about **8 times** faster\nthan `globalRand` at the concurrent situation.\n\nHowever, if you no need to share a single rand object within multiple goroutines, you could create a private rand.Rand\nobject for each goroutine.\n\n## Install\n\n```shell\ngo get github.com/joway/fastrand\n```\n\n## Usage\n\n```go\nrd := fastrand.New()\nrd.Intn(100)\n```\n\n## Benchmark\n\n```text\nBenchmarkStandardRand\nBenchmarkStandardRand-8                         60870416                19.1 ns/op             0 B/op          0 allocs/op\nBenchmarkFastRand\nBenchmarkFastRand-8                             100000000               10.7 ns/op             0 B/op          0 allocs/op\nBenchmarkUnsafetyFastRand\nBenchmarkUnsafetyFastRand-8                     100000000               10.7 ns/op             0 B/op          0 allocs/op\nBenchmarkStandardRandWithConcurrent\nBenchmarkStandardRandWithConcurrent-8           18058663                67.8 ns/op             0 B/op          0 allocs/op\nBenchmarkFastRandWithConcurrent\nBenchmarkFastRandWithConcurrent-8               132542940                8.79 ns/op            0 B/op          0 allocs/op\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoway%2Ffastrand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoway%2Ffastrand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoway%2Ffastrand/lists"}