<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 1、生成一个范围内的随机整数[minNum,maxNum]
function randomNum(minNum,maxNum){
switch(arguments.length){
case 1:
return parseInt(Math.random()*minNum+1)
break
case 2:
return parseInt(Math.random()*(maxNum-minNum+1)+minNum)
break
default:
return 0
break
}
}
console.log(randomNum(2,3))
// 2、生成一个随机的字符串
const str = Math.random().toString(36).substr(2,10)
</script>
</body>
</html>
js生成随机数和随机字符串
最新推荐文章于 2024-05-09 10:50:31 发布