mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 01:50:44 -05:00
Updates RandomUtil.randInt
to return the input when the input values are the same.
Adds a test.
This commit is contained in:
parent
90b6f28f31
commit
1074306758
@ -389,15 +389,17 @@ export class RandomUtil {
|
|||||||
* @returns A random integer within the specified range.
|
* @returns A random integer within the specified range.
|
||||||
*/
|
*/
|
||||||
public randInt(low: number, high?: number): number {
|
public randInt(low: number, high?: number): number {
|
||||||
|
if (typeof high === "undefined") {
|
||||||
|
return crypto.randomInt(0, low);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return low directly when low and high are equal
|
||||||
if (low === high) {
|
if (low === high) {
|
||||||
return low;
|
return low;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof high !== "undefined") {
|
|
||||||
return crypto.randomInt(low, high);
|
return crypto.randomInt(low, high);
|
||||||
}
|
}
|
||||||
return crypto.randomInt(0, low);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a specified number of random elements from a given list.
|
* Draws a specified number of random elements from a given list.
|
||||||
|
@ -394,6 +394,11 @@ describe("RandomUtil", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("randInt", () => {
|
describe("randInt", () => {
|
||||||
|
it("should return the same value when low and high are equal", () => {
|
||||||
|
const result = randomUtil.randInt(5, 5);
|
||||||
|
expect(result).toBe(5);
|
||||||
|
});
|
||||||
|
|
||||||
it("should return an integer between low and high - 1", () => {
|
it("should return an integer between low and high - 1", () => {
|
||||||
const low = 5;
|
const low = 5;
|
||||||
const high = 10;
|
const high = 10;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user