{"id":23931153,"url":"https://github.com/a13X-B/loaded_dice","last_synced_at":"2025-09-11T15:31:11.331Z","repository":{"id":246784107,"uuid":"822177139","full_name":"a13X-B/loaded_dice","owner":"a13X-B","description":"Walker-Vose alias method for efficiently simulating a loaded die, written in lua","archived":false,"fork":false,"pushed_at":"2024-06-30T14:54:17.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-03T02:17:41.205Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a13X-B.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-30T13:50:40.000Z","updated_at":"2024-07-03T02:18:21.217Z","dependencies_parsed_at":null,"dependency_job_id":"ca3af04d-392e-48e1-806a-81bfa0f8d2e4","html_url":"https://github.com/a13X-B/loaded_dice","commit_stats":null,"previous_names":["a13x-b/loaded_dice"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a13X-B%2Floaded_dice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a13X-B%2Floaded_dice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a13X-B%2Floaded_dice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a13X-B%2Floaded_dice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a13X-B","download_url":"https://codeload.github.com/a13X-B/loaded_dice/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232654884,"owners_count":18556472,"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":"2025-01-06T00:01:54.179Z","updated_at":"2025-01-06T00:05:23.754Z","avatar_url":"https://github.com/a13X-B.png","language":"Lua","funding_links":[],"categories":["Math"],"sub_categories":[],"readme":"# loaded_dice\nsingle file helper library that implements Walker-Vose alias method for efficiently simulating a loaded die\n\nwritten in lua\n\nuseful for rolling loot tables, spinning roulettes with non-even sectors, damage distributed status effects, you name it\n\n# api\nimport the library\n`local ld = require(\"loaded_dice\")`\n\n## create a new loaded die\n```lua\nlocal die = ld.new_die()\n```\ncreates a new loaded die\n\nalso can take a list of weights or a table as anargument\n\n## add weights\n```lua\ndie:add(weight)\n```\nadd new weighted side to the die, weights are dimensionless and the probablility will be proportional to the total weights sum\n\n## set weights\n```lua\ndie:set(index, weight)\n```\nreplace weight at existing index\n\n## read weights\n```lua\ndie:get(index)\n```\nreturns previously set weight in case you forgot what it was\n\n## generate a weighted random number\n```lua\ndie:random(random1, random2)\n```\ncan also use `die:sample(...)`\n\ntakes two random numbers in range `[0,1)` as parameters and returns a weighted random integer between 1 and number of added weights\n\n`die:random()` with no parameters will use `math.random` internally\n\n`die:random_fn(function)` will generate a random number using the provided function\n\n`die:random_gen(rng, [name])` will generate a random number using provided `rng` object, will call it by name like `rng:name()` if provided and assumes `rng:random()` by default\n\n## build alias table\n```lua\ndie:build_alias()\n```\nthe alias table will be built automatically if it's outdated at the time of calling `die:random`\n\nthis methods lets you build it manually\n\n# example\n```lua\nlocal ld = require(\"loaded_dice\")\n\nlocal loot = {\"dirt\",\"leaf\",\"stick\",\"string\",\"paperclip\",\"copper coin\"} -- possible loot\n\nlocal weights = {50,30,30,10,7,2} -- drop weights, notice how they're specifically not percentages\n\nlocal loot_die = ld.new_die(weights) -- new shiny loaded die\n\nprint(loot[loot_die:random()]) -- roll for loot! possible output: copper coin, lucky\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa13X-B%2Floaded_dice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa13X-B%2Floaded_dice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa13X-B%2Floaded_dice/lists"}