{"id":15862123,"url":"https://github.com/afeiship/next-weight-random","last_synced_at":"2026-05-05T05:32:03.492Z","repository":{"id":57122943,"uuid":"276555819","full_name":"afeiship/next-weight-random","owner":"afeiship","description":"Random has weight.","archived":false,"fork":false,"pushed_at":"2021-04-21T02:38:09.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-08T08:05:21.292Z","etag":null,"topics":["next","random","weight"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/afeiship.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-02T05:21:57.000Z","updated_at":"2021-04-21T02:38:11.000Z","dependencies_parsed_at":"2022-08-26T04:12:30.763Z","dependency_job_id":null,"html_url":"https://github.com/afeiship/next-weight-random","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeiship%2Fnext-weight-random","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeiship%2Fnext-weight-random/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeiship%2Fnext-weight-random/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeiship%2Fnext-weight-random/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afeiship","download_url":"https://codeload.github.com/afeiship/next-weight-random/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246709935,"owners_count":20821298,"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":["next","random","weight"],"created_at":"2024-10-05T22:25:18.036Z","updated_at":"2026-05-05T05:31:58.455Z","avatar_url":"https://github.com/afeiship.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# next-weight-random\n\u003e Random has weight.\n\n[![version][version-image]][version-url]\n[![license][license-image]][license-url]\n[![size][size-image]][size-url]\n[![download][download-image]][download-url]\n\n## installation\n```bash\nnpm install -S @jswork/next-weight-random\n```\n\n## usage\n```js\nimport '@jswork/next-weight-random';\n\nconst results = {};\n\nconst params1 = [ 0.75, 0.15, 0.1 ];\nconst params2 = {\n  0: 0.75,\n  1: 0.15,\n  2: 0.1\n};\n\nconst rand = nx.weightRandom(params1);\n\nfor (let i = 0; i \u003c 1000; i++) {\n  const val = rand1();\n  results[val] = results[val] || [];\n  results[val].push(true);\n}\n\nconst total = results[0].length + results[1].length + results[2].length;\n\nconsole.log(\n  results[0].length / total,\n  results[1].length / total,\n  results[2].length / total\n);\n\n// Run multple times:\n// 0.765 0.129 0.106\n// 0.751 0.152 0.097\n// 0.778 0.135 0.087\n```\n\n## resources\n- https://stackoverflow.com/questions/8435183/generate-a-weighted-random-number\n\n## license\nCode released under [the MIT license](https://github.com/afeiship/next-weight-random/blob/master/LICENSE.txt).\n\n[version-image]: https://img.shields.io/npm/v/@jswork/next-weight-random\n[version-url]: https://npmjs.org/package/@jswork/next-weight-random\n\n[license-image]: https://img.shields.io/npm/l/@jswork/next-weight-random\n[license-url]: https://github.com/afeiship/next-weight-random/blob/master/LICENSE.txt\n\n[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/next-weight-random\n[size-url]: https://github.com/afeiship/next-weight-random/blob/master/dist/next-weight-random.min.js\n\n[download-image]: https://img.shields.io/npm/dm/@jswork/next-weight-random\n[download-url]: https://www.npmjs.com/package/@jswork/next-weight-random\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafeiship%2Fnext-weight-random","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafeiship%2Fnext-weight-random","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafeiship%2Fnext-weight-random/lists"}