mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-12 15:50:42 -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,14 +389,16 @@ export class RandomUtil {
|
||||
* @returns A random integer within the specified range.
|
||||
*/
|
||||
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) {
|
||||
return low;
|
||||
}
|
||||
|
||||
if (typeof high !== "undefined") {
|
||||
return crypto.randomInt(low, high);
|
||||
}
|
||||
return crypto.randomInt(0, low);
|
||||
return crypto.randomInt(low, high);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -394,6 +394,11 @@ describe("RandomUtil", () => {
|
||||
});
|
||||
|
||||
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", () => {
|
||||
const low = 5;
|
||||
const high = 10;
|
||||
|
Loading…
x
Reference in New Issue
Block a user