Skip to main content
Module

x/fortuna/mod.ts>roll

Gacha system (random weighted selection) in TypeScript.
Go to Latest
function roll
import { roll } from "https://deno.land/x/fortuna@v3.0.2/mod.ts";

Roll one item from a pool using linear search. Simple and great for smaller pools.

Parameters

choices: ItemType[]

List of items to roll from, each having a result and chance.

chances: number[]

Total weight of the pool.

const items = [
{ result: "SSR cool character", chance: 1 },
{ result: "Kinda rare character", chance: 3 },
{ result: "Mob character", chance: 5 },
{ result: "Mob character", chance: 5 },
{ result: "Mob character", chance: 5 },
]
roll(items) // Rolls one item from the list of items
const items = [
{ result: "SSR cool character", chance: 1 },
{ result: "Kinda rare character", chance: 3 },
{ result: "Mob character", chance: 5 },
{ result: "Mob character", chance: 5 },
{ result: "Mob character", chance: 5 },
]
roll(items, 19) // Rolls one item from the list of items, faster because the total chance is known.
optional
totalChance: number

Parameters

choices: GachaChoice<ItemType>[]
optional
totalChance: number