Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Javascript get random number in a specific range
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {float} a random floating point number
*/
function getRandom(min, max) {
return Math.random() * (max - min) + min;
}
/**
* Get a random integer between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {int} a random integer
*/
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
@neurotech

Thanks for this - it came in useful and helped me solve a problem today. :grinning:

@kerimdzhanov
Owner

Always welcome! Glad to know that it's helpful. :)

@alvarod-infocorp

Thanks, it's just I need

@Verten

Thanks!

@cjseeger

Very Helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.