- public static getRandomFloat(max: number, min = 0): number {
- return (crypto.randomBytes(4).readUInt32LE() / 0xffffffff) * (max - min) + min;
+ public static getRandomFloat(max: number, min = 0, negative = false): number {
+ const randomPositiveFloat = crypto.randomBytes(4).readUInt32LE() / 0xffffffff;
+ const sign = (negative && randomPositiveFloat < 0.5) ? 1 : -1;
+ return sign * (randomPositiveFloat * (max - min) + min);