speice.io/blog/2024-11-15-playing-with-fire/utility.ts

29 lines
603 B
TypeScript
Raw Normal View History

2024-11-16 18:20:32 -05:00
/**
* Generate a uniform random number in the range (-1, 1)
*
* @returns
*/
export function randomBiUnit() {
return Math.random() * 2 - 1;
}
/**
* Generate a uniform random integer in the range [min, max)
*
* @param min
* @param max
* @returns
*/
export function randomInteger(min: number, max: number) {
return Math.floor(Math.random() * (max - min)) + min;
}
// https://stackoverflow.com/a/34356351
export function hexToBytes(hex: string) {
var bytes = [];
for (var i = 0; i < hex.length; i += 2) {
bytes.push(parseInt(hex.substring(i, i + 2), 16));
}
return bytes;
}