我需要它来生成随机网址,例如:http://example.com/random/ab8536dc2e
我将如何生成这样的网址?
我相信我的回答可能会某种程度上违反论坛规则,因为您没有向我们展示您的解决方案或尝试过的内容。
但是我想我可以用这个简单的脚本来帮助您,并且条件是下次您提出问题时,请提供一些信息和代码。
玩得开心:
function forgeUrlAccessPoint(url=false, randomKeyLength=10){
if(!url)
url = location.origin;
const allowedCodes = "azertyuiopmlkjhgfdsqwxcvbn0123456789";
let randomKey = "";
while(randomKey.length<randomKeyLength){
const randIndex = Math.Between(0, allowedCodes.length);
console.log( randIndex );
}
}
Math.Between = function(min, max){
return Math.floor(Math.random() * (max - min) + min);
}
<button onclick="forgeUrlAccessPoint()">Generate Now</button>
function forgeUrlAccessPoint(url=false, randomKeyLength=10){
if(!url)
url = location.origin;
const allowedCodes = "azertyuiopmlkjhgfdsqwxcvbn0123456789";
let randomKey = "";
while(randomKey.length<randomKeyLength){
const randIndex = Math.Between(0, allowedCodes.length);
randomKey += randIndex%2==0?allowedCodes[randIndex]:allowedCodes[randIndex].toUpperCase();
}
return url+"/"+randomKey.substr(0, randomKeyLength);
}
Math.Between = function(min, max){
return Math.floor(Math.random() * (max - min) + min);
}
<button onclick="alert(forgeUrlAccessPoint('https://www.example.com/random'))">Generate Now</button>