Javascript Random Number?

前端 未结 3 1706
傲寒
傲寒 2020-12-16 14:14

I have the following script:

Timer=0;
function countdown(auctionid){
    var auctions;
    var divs;

    Timer=Timer+1;

    if((Timer%10==\"0\")||(Timer==\         


        
3条回答
  •  离开以前
    2020-12-16 14:26

    You want to use the random() function. There is no version that returns an integer unfortunately, only a float between 0 and 1, so you'll need to do a few operations. Try the following:

    var randomNum = Math.floor(Math.random() * 10) + 2;
    

    This should generate a random integral number between 2 (inclusive) and 12 (exclusive). Change 10 to 11 if you want the 12 to be inclusive, of course.

提交回复
热议问题