Home >Web Front-end >JS Tutorial >JS implements random number code sharing

JS implements random number code sharing

小云云
小云云Original
2018-02-26 09:11:091593browse

This article mainly shares with you JS to implement random number code sharing. Random numbers are often used when making web pages or small programs. The author has compiled a very simple JS program to generate random numbers. I hope this article can help everyone.

Let’s first take a look at the renderings of this source code

You can use it flexibly, we will share the specific JS code with you:


<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Document</title> 
<style> 
  #count{ 
    font-size: 20px; 
    color: green; 
    width: 400px; 
    height: 30px; 
    border: 1px solid black; 
    margin: auto; 
    line-height: 30px; 
    text-align: center; 
  } 
  </style> 
</head> 
<body> 
  <p id="count"></p> 
  <script> 
  //产生随机数 
function count (){ 
  var i=Math.random()*(999999-100000)+100000; 
  var j=parseInt(i,10); 
  j="100000-999999随机产生:"+j; 
  document.getElementById("count").innerHTML= j; 
} 
setInterval("count()",100); 
  </script> 
</body> 
</html>

If you have a simpler method, you can discuss it in the message area below.

Related recommendations:

Javascript generates random number examples to share

JavaScript random number generator implementation method

Javascript summary of several methods of generating random numbers


The above is the detailed content of JS implements random number code sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn