首頁  >  問答  >  主體

老师,随机问题用floor方法,永远取不要最大值,为什么不用round?

Math.floor(Math.random()*(max-min)+min);//取不到max

Math.round(Math.random()*(max-min)+min);//可以取到min,也可以取到max,更合理一点



RJRJ2798 天前1126

全部回覆(2)我來回復

  • 数据分析师

    数据分析师2017-10-01 00:27:59

    老師,隨機問題用floor方法,永遠取不要最大值,為什麼不用round? -PHP中文網問答-老師,隨機問題用floor法,永遠取不要最大值,為什麼不用round? -PHP中文網問答

    圍觀一下哦,學習一下。

    回覆
    0
  • 阿神

    阿神2017-02-22 09:17:03

    嗯,是的,确实更合理点,你思考的很仔细

    回覆
    0
  • 取消回覆