Skip to main content

A TypeScript module for random events and gacha.

Works with
It is unknown whether this package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
88%
Published
3 months ago (4.1.3)

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"
]
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @nekooftheabyss/fortuna

Import symbol

import * as mod from "@nekooftheabyss/fortuna";

Add Package

npx jsr add @nekooftheabyss/fortuna

Import symbol

import * as mod from "@nekooftheabyss/fortuna";

Add Package

yarn dlx jsr add @nekooftheabyss/fortuna

Import symbol

import * as mod from "@nekooftheabyss/fortuna";

Add Package

pnpm dlx jsr add @nekooftheabyss/fortuna

Import symbol

import * as mod from "@nekooftheabyss/fortuna";

Add Package

bunx jsr add @nekooftheabyss/fortuna

Import symbol

import * as mod from "@nekooftheabyss/fortuna";