{"id":16801889,"url":"https://github.com/valyala/fastrand","last_synced_at":"2025-04-13T05:06:09.751Z","repository":{"id":53602495,"uuid":"87937474","full_name":"valyala/fastrand","owner":"valyala","description":"Fast and scalable pseudorandom generator for Go","archived":false,"fork":false,"pushed_at":"2021-09-15T05:59:43.000Z","size":8,"stargazers_count":206,"open_issues_count":1,"forks_count":16,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-13T05:06:05.517Z","etag":null,"topics":["fast","go","golang","random-number-generators","scalable"],"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/valyala.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":"2017-04-11T13:28:59.000Z","updated_at":"2025-03-27T14:15:19.000Z","dependencies_parsed_at":"2022-09-26T17:41:15.753Z","dependency_job_id":null,"html_url":"https://github.com/valyala/fastrand","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valyala%2Ffastrand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valyala%2Ffastrand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valyala%2Ffastrand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valyala%2Ffastrand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valyala","download_url":"https://codeload.github.com/valyala/fastrand/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665749,"owners_count":21142123,"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":["fast","go","golang","random-number-generators","scalable"],"created_at":"2024-10-13T09:38:07.056Z","updated_at":"2025-04-13T05:06:09.732Z","avatar_url":"https://github.com/valyala.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/valyala/fastrand.svg)](https://travis-ci.org/valyala/fastrand)\n[![GoDoc](https://godoc.org/github.com/valyala/fastrand?status.svg)](http://godoc.org/github.com/valyala/fastrand)\n[![Go Report](https://goreportcard.com/badge/github.com/valyala/fastrand)](https://goreportcard.com/report/github.com/valyala/fastrand)\n\n\n# fastrand\n\nFast pseudorandom number generator.\n\n\n# Features\n\n- Optimized for speed.\n- Performance scales on multiple CPUs.\n\n# How does it work?\n\nIt abuses [sync.Pool](https://golang.org/pkg/sync/#Pool) for maintaining\n\"per-CPU\" pseudorandom number generators.\n\nTODO: firgure out how to use real per-CPU pseudorandom number generators.\n\n\n# Benchmark results\n\n\n```\n$ GOMAXPROCS=1 go test -bench=. github.com/valyala/fastrand\ngoos: linux\ngoarch: amd64\npkg: github.com/valyala/fastrand\nBenchmarkUint32n                   \t50000000\t        29.7 ns/op\nBenchmarkRNGUint32n                \t200000000\t         6.50 ns/op\nBenchmarkRNGUint32nWithLock        \t100000000\t        21.5 ns/op\nBenchmarkMathRandInt31n            \t50000000\t        31.8 ns/op\nBenchmarkMathRandRNGInt31n         \t100000000\t        17.9 ns/op\nBenchmarkMathRandRNGInt31nWithLock \t50000000\t        30.2 ns/op\nPASS\nok  \tgithub.com/valyala/fastrand\t10.634s\n```\n\n```\n$ GOMAXPROCS=2 go test -bench=. github.com/valyala/fastrand\ngoos: linux\ngoarch: amd64\npkg: github.com/valyala/fastrand\nBenchmarkUint32n-2                     \t100000000\t        17.6 ns/op\nBenchmarkRNGUint32n-2                  \t500000000\t         3.36 ns/op\nBenchmarkRNGUint32nWithLock-2          \t50000000\t        32.0 ns/op\nBenchmarkMathRandInt31n-2              \t20000000\t        51.2 ns/op\nBenchmarkMathRandRNGInt31n-2           \t100000000\t        11.0 ns/op\nBenchmarkMathRandRNGInt31nWithLock-2   \t20000000\t        91.0 ns/op\nPASS\nok  \tgithub.com/valyala/fastrand\t9.543s\n```\n\n```\n$ GOMAXPROCS=4 go test -bench=. github.com/valyala/fastrand\ngoos: linux\ngoarch: amd64\npkg: github.com/valyala/fastrand\nBenchmarkUint32n-4                     \t100000000\t        14.2 ns/op\nBenchmarkRNGUint32n-4                  \t500000000\t         3.30 ns/op\nBenchmarkRNGUint32nWithLock-4          \t20000000\t        88.7 ns/op\nBenchmarkMathRandInt31n-4              \t10000000\t       145 ns/op\nBenchmarkMathRandRNGInt31n-4           \t200000000\t         8.35 ns/op\nBenchmarkMathRandRNGInt31nWithLock-4   \t20000000\t       102 ns/op\nPASS\nok  \tgithub.com/valyala/fastrand\t11.534s\n```\n\nAs you can see, [fastrand.Uint32n](https://godoc.org/github.com/valyala/fastrand#Uint32n)\nscales on multiple CPUs, while [rand.Int31n](https://golang.org/pkg/math/rand/#Int31n)\ndoesn't scale. Their performance is comparable on `GOMAXPROCS=1`,\nbut `fastrand.Uint32n` runs 3x faster than `rand.Int31n` on `GOMAXPROCS=2`\nand 10x faster than `rand.Int31n` on `GOMAXPROCS=4`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalyala%2Ffastrand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalyala%2Ffastrand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalyala%2Ffastrand/lists"}