hermes/api/src/libs/generateRandom.ts
greysoh 42a6d2ea02
chore: Adds formatting.
Co-authored-by: dess <devessa@users.noreply.github.com>
2024-05-05 16:59:08 -04:00

22 lines
582 B
TypeScript

function getRandomInt(min: number, max: number): number {
const minCeiled = Math.ceil(min);
const maxFloored = Math.floor(max);
return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled); // The maximum is exclusive and the minimum is inclusive
}
export function generateRandomData(length: number = 128): string {
let newString = "";
for (let i = 0; i < length; i += 2) {
const randomNumber = getRandomInt(0, 255);
if (randomNumber == 0) {
i -= 2;
continue;
}
newString += randomNumber.toString(16);
}
return newString;
}