Skip to content
Jason Godesky edited this page Jul 18, 2026 · 1 revision

chance returns a boolean based on the odds given.

Parameters

chances: number

The chances of returning true (the x in a “x chances in y”; e.g., for “1 chance in 100,” chances would be 1).

Default: 1

total: number

The total possibilities (the y in a “x chances in y”; e.g., for “1 chance in 100,” total would be 100).

Default: 100

Returns

A boolean, with the chances of the value being true or false being based on the odds provided.

Examples

import { chance } from '@revolutionarygamesco/common'

chance(1, 2) // This has a 50% chance of returning true, 50% chance of false
chance(50, 100) // Also 50/50
chance(1, 100) // This has a 1% chance of returning true, 99% chance of false
chance(7, 10) // This has a 70% chance of return true, 30% chance of returning false

Clone this wiki locally