First commit

This commit is contained in:
2023-12-07 20:35:55 +01:00
parent 3480f2ab05
commit ea881e2403
18 changed files with 668 additions and 0 deletions

20
api/modules/random.js Normal file
View File

@@ -0,0 +1,20 @@
export function random(x, y) {
return crypto.randomInt(x, y + 1);
}
export function random2(min, max) {
const range = max - min + 1;
const byteLength = Math.ceil(Math.log2(range) / 8);
let randomValue;
do {
const randomBytes = crypto.randomBytes(byteLength);
randomValue = parseInt(randomBytes.toString('hex'), 16);
} while (randomValue >= range);
return randomValue + min;
}
export function randomHEX(x) {
return crypto.randomBytes(x).toString('hex');
}