Open
Description
Generating random numbers is a very common task in any language. By looking at discussions on StackOverflow such as [1] and [2] and the relevant MDN page, it's clear that many developers would benefit from such method. Not that it's really hard to implement using Math.random()
but other utility methods have been added to JavaScript to facilitate developers' life.
My preference would go to the version that includes both the boundaries. So, the implementation should be something like:
Math.randomInt = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};