Skip to main content
Module

x/fortuna/mod.ts

A TypeScript module for random events and gacha.
Latest
import * as fortuna from "https://deno.land/x/fortuna@v4.1.3/mod.ts";

The quick solution for everything random! A Gacha-like system to roll random items with weights.

More weight = more common. Think of it as in terms of probability.

// deno.land
import { GachaMachine } from "https://deno.land/x/fortuna/mod.ts"
// JSR
import { GachaMachine } from "jsr:@nekooftheabyss/fortuna@4.1.3"
// Node
import { GachaMachine } from "@nekooftheabyss/fortuna"
// esm.sh
import { GachaMachine } from "https://esm.sh/jsr/@nekooftheabyss/fortuna@4.1.3"

const items = [
   { result: "SSR cool character", chance: 1 },
   { result: "Kinda rare character", chance: 3 },
   { result: "Mob character #1", chance: 5 },
   { result: "Mob character #2", chance: 5 },
   { result: "Mob character #3", chance: 5 },
]

const machine = new GachaMachine(items)

machine.get(10) // Rolls 10x

My result:

[
    "Kinda rare character",
    "Mob character #1",
    "Mob character #3",
    "Mob character #3",
    "Mob character #1",
    "Kinda rare character",
    "Mob character #2",
    "Mob character #2" ,
    "Mob character #1",
    "Mob character #2"
]

Classes

Gacha system.

Gacha system for rolling n distinct items from the weighted collection.

Functions

Roll one item from a pool using linear search. Simple and great for one-time use pools. Use GachaMachine if you will be picking multiple items from the same pool.

Roll an unbiased die. A biased die can be implemented using GachaMachine.

Toss n unbiased coins (50% chance of head / tail). A biased coin can be implemented using GachaMachine. Do not toss more than 62 coins at once.