首页  >  问答  >  正文

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

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

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



RJRJ2798 天前1127

全部回复(2)我来回复

  • 数据分析师

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

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

    围观一下哦,学习一下。

    回复
    0
  • 阿神

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

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

    回复
    0
  • 取消回复