@tdb/util
Version:
Shared helpers and utilities.
18 lines (16 loc) • 427 B
text/typescript
/**
* Rounds to the given precision
*/
export function round(value: number, precision: number = 0) {
const multiplier = Math.pow(10, precision || 0);
return Math.round(value * multiplier) / multiplier;
}
/**
* Generates a random number.
*/
export function random(min: number = 0, max?: number): number {
if (max === undefined) {
max = min + 999;
}
return Math.floor(Math.random() * (max - min + 1) + min);
}