bitburner-src/utils/helpers/getRandomInt.ts

12 lines
380 B
TypeScript
Raw Normal View History

/**
* Gets a random integer bounded by the values passed in.
* @param min The minimum value in the range.
* @param max The maximum value in the range.
*/
2021-05-01 09:17:31 +02:00
export function getRandomInt(min: number, max: number): number {
2021-09-05 01:09:30 +02:00
const lower: number = Math.min(min, max);
const upper: number = Math.max(min, max);
2021-09-05 01:09:30 +02:00
return Math.floor(Math.random() * (upper - lower + 1)) + lower;
}