mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-20 16:22:56 +02:00
[refactor] Moved getRandombyte to its own TS file
Also made use of `getRandomInt`
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
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).
|
||||
*/
|
||||
export function getRandomByte(max: number) {
|
||||
// Technically 2^8 is 256, but the values are 0-255, not 1-256.
|
||||
const byteMaximum: number = 255;
|
||||
const upper: number = Math.max(Math.min(max, byteMaximum), 0);
|
||||
|
||||
return getRandomInt(0, upper);
|
||||
}
|
||||
Reference in New Issue
Block a user