* Generate a cryptographically random integer in the range [0, max)
(max: number)
| 765 | * Generate a cryptographically random integer in the range [0, max) |
| 766 | */ |
| 767 | function randomInt(max: number): number { |
| 768 | // Use crypto.randomBytes for better randomness than Math.random |
| 769 | const bytes = randomBytes(4) |
| 770 | const value = bytes.readUInt32BE(0) |
| 771 | return value % max |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * Pick a random element from an array |