diff --git a/utils/random.ts b/utils/random.ts index d21122f4..30eb3d2d 100644 --- a/utils/random.ts +++ b/utils/random.ts @@ -1,8 +1,13 @@ -const randFromArray = (array: any[]) => array[Math.floor(Math.random() * array.length)] +import {randomBytes} from 'crypto' -const randIntFromInterval = (min: number, max: number) => Math.floor(Math.random() * (max - min) + min) +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 + randIntFromInterval, + random } diff --git a/utils/string.ts b/utils/string.ts index ae315aa0..03197f01 100644 --- a/utils/string.ts +++ b/utils/string.ts @@ -1,5 +1,7 @@ +import {random} from './random' + const capitalise = (s: string) => s.charAt(0).toUpperCase() + s.slice(1) -const shuffle = (s: string) => s.split('').sort(() => 0.5 - Math.random()).join('') +const shuffle = (s: string) => s.split('').sort(() => 0.5 - random()).join('') export {capitalise, shuffle}