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