JS代碼:
function s20(){
var data=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];
for(var j=0;j<500;j++){ //500為想要產生的行數
var result="";
for(var i=0;i<20;i++){ //產生20位就使i<20
r=Math.floor(Math.random()*16); //16為數組裡面數據的數量,目的是以此當下標取數組data裡的值!
result+=data[r]; //輸出20次隨機數的同時,讓rrr加20次,就是20位的隨機字符串了。
}
document.write(result);
document.write("<br/>");
} }
完整html代碼:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
function s20(){
var data=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];
for(var j=0;j<500;j++){
var result="";
for(var i=0;i<20;i++){
r=Math.floor(Math.random()*16);
result+=data[r];
}
document.write(result);
document.write("<br/>");
} }
</script>
</head>
<body>
<input type="button" onclick="s20()" value="產生隨機數">
</body>
</html>