{"id":13801446,"url":"https://github.com/retraigo/fortuna","last_synced_at":"2025-03-16T13:31:49.844Z","repository":{"id":37982172,"uuid":"471992611","full_name":"retraigo/fortuna","owner":"retraigo","description":"A TypeScript module for random events and gacha (random sampling with weights).","archived":false,"fork":false,"pushed_at":"2025-03-15T03:37:35.000Z","size":635,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T04:24:41.536Z","etag":null,"topics":["deno","dice","gacha","random","toss-a-coin","typescript","weighted-random-choice"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/retraigo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","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},"funding":{"github":"retraigo","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-03-20T13:45:14.000Z","updated_at":"2025-03-15T03:36:41.000Z","dependencies_parsed_at":"2024-02-21T04:32:42.221Z","dependency_job_id":"f3ab8aeb-d80b-4197-af63-ef3ffef50302","html_url":"https://github.com/retraigo/fortuna","commit_stats":{"total_commits":69,"total_committers":4,"mean_commits":17.25,"dds":"0.23188405797101452","last_synced_commit":"faba2177237387d89e06c044ea681ba714ec4e10"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retraigo%2Ffortuna","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retraigo%2Ffortuna/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retraigo%2Ffortuna/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/retraigo%2Ffortuna/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/retraigo","download_url":"https://codeload.github.com/retraigo/fortuna/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243685039,"owners_count":20330972,"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":["deno","dice","gacha","random","toss-a-coin","typescript","weighted-random-choice"],"created_at":"2024-08-04T00:01:22.906Z","updated_at":"2025-03-16T13:31:49.470Z","avatar_url":"https://github.com/retraigo.png","language":"TypeScript","funding_links":["https://github.com/sponsors/retraigo"],"categories":["Modules"],"sub_categories":["Utils"],"readme":"# Fortuna\nThe quick solution for everything random!\n\nA Gacha-like system to roll random items with weights.\n\n## Usage\n\nMore weight = more common. Think of it as in terms of probability.\n\n```js\n// Deno\nimport { GachaMachine } from \"https://deno.land/x/fortuna/mod.ts\"\n// JSR\nimport { GachaMachine } from \"jsr:@nekooftheabyss/fortuna@4.1.3\"\n// Node\nimport { GachaMachine } from \"@nekooftheabyss/fortuna\"\n// esm.sh\nimport { GachaMachine } from \"https://esm.sh/jsr/@nekooftheabyss/fortuna@4.1.3\"\n\nconst items = [\n    { result: \"SSR cool character\", chance: 1 },\n    { result: \"Kinda rare character\", chance: 3 },\n    { result: \"Mob character #1\", chance: 5 },\n    { result: \"Mob character #2\", chance: 5 },\n    { result: \"Mob character #3\", chance: 5 },\n]\n\nconst machine = new GachaMachine(items)\n\nmachine.get(10) // Rolls 10x\n\n/*\n    My result:\n    [\n      \"Kinda rare character\",\n      \"Mob character #1\",\n      \"Mob character #3\",\n      \"Mob character #3\",\n      \"Mob character #1\",\n      \"Kinda rare character\",\n      \"Mob character #2\",\n      \"Mob character #2\" ,\n      \"Mob character #1\",\n      \"Mob character #2\"\n    ]\n*/\n```\n\n### Rolling distinct elements\nYou can roll distinct elements using the `LimitedGachaMachine`. It is slower\nthan `GachaMachine` but there shouldn't be much noticeable difference.\n\nThe \"distinct\" behavior only applies to within a single `.get()` call. It\ndoesn't affect the pool of items used when initializing `new LimitedGachaMachine()`.\n\n```js\n\nimport { LimitedGachaMachine } from \"https://deno.land/x/fortuna/mod.ts\"\n// JSR\nimport { LimitedGachaMachine } from \"jsr:@nekooftheabyss/fortuna@4.1.3\"\n\nconst items = [\n    { result: \"SSR cool character\", chance: 1 },\n    { result: \"Kinda rare character\", chance: 3 },\n    { result: \"Mob character #1\", chance: 5 },\n    { result: \"Mob character #2\", chance: 5 },\n    { result: \"Mob character #3\", chance: 5 },\n]\n\nconst machine = new LimitedGachaMachine(items)\n\nmachine.get(4) // Rolls 4x\n\n/*\n    My result:\n    [\n      \"Kinda rare character\",\n      \"Mob character #1\",\n      \"Mob character #3\",\n      \"Mob character #2\",\n    ]\n*/\n```\n\n### Plain weighted random selection\n\nYou probably don't need all complicated stuff. Here's a quick way to just create a simple weight-based gacha system:\n(Only works on v3.0.1 and above)\n\n```ts\nimport { roll } from \"jsr:@nekooftheabyss/fortuna@4.1.3/roll\"; // wherever you are importing from.\n\nconst items = [\n    { result: \"SSR cool character\", chance: 1 },\n    { result: \"Kinda rare character\", chance: 3 },\n    { result: \"Mob character #1\", chance: 5 },\n    { result: \"Mob character #2\", chance: 5 },\n    { result: \"Mob character #3\", chance: 5 },\n];\n\nroll(items); // Rolls one item from the list of items using linear search.\n```\n\nYou can also provide two individual arrays for choices and weights.\n\n```ts\nimport { roll } from \"jsr:@nekooftheabyss/fortuna@4.1.3/roll\"; // wherever you are importing from.\n\nconst items = [\n    \"SSR cool character\",\n    \"Kinda rare character\",\n    \"Mob character #1\",\n    \"Mob character #2\",\n    \"Mob character #3\",\n];\nconst chances = [1, 3, 5, 5, 5];\n\nroll(items, chances); // Rolls one item from the list of items using linear search.\n```\n\nProviding the total chance may result in faster rolls.\n\n```ts\nimport { roll } from \"jsr:@nekooftheabyss/fortuna@4.1.3/roll\"; // wherever you are importing from.\n\nconst items = [\n    { result: \"SSR cool character\", chance: 1 },\n    { result: \"Kinda rare character\", chance: 3 },\n    { result: \"Mob character #1\", chance: 5 },\n    { result: \"Mob character #2\", chance: 5 },\n    { result: \"Mob character #3\", chance: 5 },\n];\n\nroll(items, 19); // Rolls one item from the list of items using linear search.\n```\n\n```ts\nimport { roll } from \"jsr:@nekooftheabyss/fortuna@4.1.3/roll\"; // wherever you are importing from.\n\nconst items = [\n    \"SSR cool character\",\n    \"Kinda rare character\",\n    \"Mob character #1\",\n    \"Mob character #2\",\n    \"Mob character #3\",\n];\nconst chances = [1, 3, 5, 5, 5];\n\nroll(items, chances, 19); // Rolls one item from the list of items using linear search.\n```\n\n## Documentation\n\nDocumentation for the latest version can be found in [jsr:@nekooftheabyss/fortuna](https://jsr.io/@nekooftheabyss/fortuna)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fretraigo%2Ffortuna","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fretraigo%2Ffortuna","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fretraigo%2Ffortuna/lists"}