JS generates a 20 bit random number which can be a minus 9 or a minus z

  • 2020-03-30 03:40:04
  • OfStack

JS code:


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 is the number of rows you want to generate
var result="";
for(var i=0;i<20;i++){ //Producing 20 bits makes. 20
r=Math.floor(Math.random()*16); //16 is the number of data in the array, the purpose is to take the value of the array data when the index!
result+=data[r]; //When you print out 20 random Numbers, you add RRR 20 times, which is a 20-bit random string.
} 
document.write(result); 
document.write("<br/>"); 
} }

Full HTML code:


<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=" Generate random number "> 
</body> 
</html>

Related articles: