Closed
Description
Is your feature request related to a problem? Please describe.
There is no API to obtain a random integer within a range. It's a common enough problem to deal with (e.g. to implement other algorithms like Fisher–Yates shuffle) and easy to get wrong. Most other runtimes/languages implement this in their standard library.
Describe the solution you'd like
// something like:
const randomInt = require('crypto').randomInt
const min = 0
const max = 10
randomInt(min, max, cb)
Describe alternatives you've considered
I'm not sure about the internal implementation but I gave it a stab here: https://github.com/olalonde/crypto-range. http://www.pcg-random.org/posts/bounded-rands.html has a nice overview of different techniques (my implementation is probably not the most efficient).