Skip to content

Instantly share code, notes, and snippets.

@destinmoulton
Last active February 11, 2020 23:32
Show Gist options
  • Select an option

  • Save destinmoulton/a4f05918e1ef81a2dbedfd052a84c115 to your computer and use it in GitHub Desktop.

Select an option

Save destinmoulton/a4f05918e1ef81a2dbedfd052a84c115 to your computer and use it in GitHub Desktop.
JS JavaScript
/**
* This is a function.
*
* @param {string} n - A string param
* @return {string} A good string
*
* @example
*
* foo('hello')
*/
function foo(n) { return n }
/**
* Return a Promise
*
* @returns {Promise}
* @resolve {string} Description
* @reject {Error}
*/
/**
* From MDN
* URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
*/
/**
* Generate a random arbitrary number
* that is not less than min (inclusive)
* and is less than max(exclusive).
*
* @param int min
* @param int max
*/
function getRandomArbitrary(min, max){
return Math.random() * (max - min) + min;
}
/**
* Generate a random integer between and
* including min and max.
*
* @param int min
* @param int max
*/
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment