Created
January 16, 2018 03:49
-
-
Save roshanca/04c51b175de8abf8ae20c623d47dda34 to your computer and use it in GitHub Desktop.
生成指定位数的随机数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 生成指定位数的随机数 | |
* @param {number} x | |
*/ | |
export const randomStr = (x) => { | |
let s = ""; | |
while(s.length < x && x > 0){ | |
let v = Math.random() < 0.5 ? 32 : 0; | |
s += String.fromCharCode(Math.round(Math.random() * ((122 - v) - (97 - v)) + (97 - v))); | |
} | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment