This article describes the method of JS to simply generate random numbers between two numbers. Share it for your reference, as follows:
The screenshot of the running effect is as follows:
The complete code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>Generate random numbers</title></head><body><input type="text" id="num"> <input type="button" onClick="setRnd()" value="generate random numbers between 5-10"><script type="text/javascript">function rnd(min, max){ return min + Math.floor(Math.random() * (max - min + 1));}function setRnd(){ document.getElementById("num").value = rnd(5,10);}</script></body></html>For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript Mathematical Operation Usage", "Summary of JSON Operation Skills in JavaScript", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Data Structures and Algorithm Skills" and "Summary of JavaScript Traversal Algorithm and Skills"
I hope this article will be helpful to everyone's JavaScript programming.