bitburner-src/utils/helpers/getRandomByte.ts

14 lines
427 B
TypeScript
Raw Normal View History

import { getRandomInt } from "./getRandomInt";
/**
* Gets a random value in the range of a byte (0 - 255), or up to the maximum.
* @param max The maximum value (up to 255).
*/
2021-05-01 09:17:31 +02:00
export function getRandomByte(max: number): number {
2021-09-05 01:09:30 +02:00
// Technically 2^8 is 256, but the values are 0-255, not 1-256.
const byteMaximum = 255;
const upper: number = Math.max(Math.min(max, byteMaximum), 0);
2021-09-05 01:09:30 +02:00
return getRandomInt(0, upper);
}