rundomath
v1.1.1
Published
Generate random number within a given range.
Maintainers
Readme
rundomath
Lightweight utility library for generating random numbers in a range.
Installation
npm install rundomathor with Yarn:
yarn add rundomathUsage
import { random, randomFloat } from "rundomath";
// Integer between 1 and 10 (inclusive)
const intValue = random(1, 10);
// Float between 0 and 1 (inclusive of 0, up to 1 + small epsilon)
const floatValue = randomFloat(0, 1);API
random(min: number, max: number): number
Returns a random integer betweenminandmax(inclusive).randomFloat(min: number, max: number): number
Returns a random floating-point number in the range (mintomax + 1) usingMath.random() * (max - min + 1) + min.
Examples
// Roll a six-sided die
const dieRoll = random(1, 6);
// Random temperature between -10.0 and 35.0
const temperature = randomFloat(-10, 35);License
MIT
