js随机数[0,100]与[0,100)

322 阅读1分钟
  1. [0,100)

    Math.floor(Math.random() * 100);//产生0~99.999...的随机数,并向下取整

2.[0,100] Math.floor(Math.random() * 101);//产生0~100.999...的随机数,并向下取整

3.[n,m] Math.floor(Math.random() * (m - n + 1)) + n;

4.[n,m) Math.floor(Math.random() * (m-n)) + n;