Skip to content

Instantly share code, notes, and snippets.

@ssdemajia
Created October 17, 2018 06:05
Show Gist options
  • Save ssdemajia/2680979dced6ed043686b4fd6349d210 to your computer and use it in GitHub Desktop.
Save ssdemajia/2680979dced6ed043686b4fd6349d210 to your computer and use it in GitHub Desktop.
Javascript 小函数~
function getRandom(low, up) {
// 获得包括low和up范围内的随机整数
var nums = up - low + 1;
return Math.floor(Math.random() * nums + low); // Math.floor向下取整 , 2.6 = 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment