当前位置:网站首页>JS implementation generates a random key of specified length
JS implementation generates a random key of specified length
2022-07-28 22:28:00 【A little square】
js The implementation generates a random specified length key
function generateKey(keyLength = 18) {
let rlt = ''
for (let i = 0; i < keyLength; i++) {
if (Math.round(Math.random())) {
rlt += Math.ceil(Math.random() * 9)
} else {
const ranNum = Math.ceil(Math.random() * 23)
if (Math.round(Math.random())) {
rlt += String.fromCharCode(65 + ranNum)
} else {
rlt += String.fromCharCode(97 + ranNum)
}
}
// add -, What you don't want can be removed
if ((i + 1) % 6 === 0 && i > 2 && i < 17) {
rlt += '-'
}
}
return rlt
}
key It consists of an array and upper and lower case letters , Intermediate use - Division
const a = generateKey(16) // 91Sw86-t1P3UI-B6Sx
const b = generateKey() // b4TGq1-42Se7m-49d233
const c = generateKey(20) // n44Ix5-VIU8r5-J7b8I5E2
边栏推荐
- Ruiji takeout project - development of business development function Day2
- 网易云信 2022Q2 产品补给站,快来获取你的产品补给计划吧!
- 32. Longest valid bracket (difficult stack string)
- Sword finger offer II 067. maximum XOR (medium prefix tree bit operation array)
- Brief introduction to PCB materials
- Data visualization news, different forms of news reports
- 静态成员static详解
- Is mov format a still image file format
- Mysql内置函数
- Less than a year after its establishment! MIT derivative quantum computing company completed financing of US $9million
猜你喜欢
随机推荐
The applet listens for the target node to appear on the screen
AWK空行过滤
IFLYTEK written examination
XXX port is already in use
局域网添加DNS服务器进行域名解析
76. Minimum coverage substring (hard sliding window hash table string)
How about the actual use effect of common source oscilloscope
40. Combined sum II
Brief introduction to PCB materials
From Web3 to web2.5, is it backward or another way?
[leetcode] maximum depth of binary tree
Sword finger offer II 055. Binary search tree iterator (medium binary search tree iterator)
tutorial/detailed_workflow.ipynb 量化金融Qlib库
The binary search boundary value processing based on leetcode35 is used to clarify the boundary value of the judgment condition using the idea of interval
What is the difference between inline elements and block level elements? Semantic function
Ultra detailed visual studio 2019 running littlevgl (lvgl) simulator
SQL注入 Less34(POST型宽字节注入+布尔盲注)
[LiteratureReview]Object Detection and Mapping with Bounding Box Constraints
array_diff_assoc 元素是数组时不比较数组值的办法
静态成员static详解







![[Ruiji takeout project] Day5 - Chapter 6 mobile verification code login](/img/53/c578e0d1428ea569fb412a20019924.png)
