Javascript / html:如何在数字A和数字B之间生成随机数字?

问题描述:

我们有一个带有2个字段和一个按钮的表单。我们希望通过按钮单击来输出位于int A和int B之间的随机int数(如3,5或33)? (不需要使用jQuery或类似的东西)

We have a form with 2 fields and a button. We want on button click to output random int number (like 3, 5 or 33) which would lie between int A and int B? (no use of jQuery or anything like it is required)

您可以使用Javascript Math.random

You can use Javascript Math.random

function randomInRange(start,end){
       return Math.floor(Math.random() * (end - start + 1) + start);
}