1
0
Fork 0
mirror of https://github.com/CorentinTh/it-tools.git synced 2025-07-22 22:59:37 +02:00
it-tools/utils/random.ts
2021-05-31 22:53:28 +02:00

13 lines
347 B
TypeScript

import {randomBytes} from 'crypto'
const random = () => randomBytes(4).readUInt32LE(0) / 0x100000000
const randFromArray = (array: any[]) => array[Math.floor(random() * array.length)]
const randIntFromInterval = (min: number, max: number) => Math.floor(random() * (max - min) + min)
export {
randFromArray,
randIntFromInterval,
random
}