mirror of
https://github.com/bspeice/speice.io
synced 2024-12-23 00:58:09 -05:00
29 lines
603 B
TypeScript
29 lines
603 B
TypeScript
|
/**
|
||
|
* 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;
|
||
|
}
|