search

Home  >  Q&A  >  body text

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

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

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



RJRJ2886 days ago1182

reply all(2)I'll reply

  • 数据分析师

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

    Teacher, use the floor method for random questions and never take the maximum value. Why not use round? -PHP Chinese website Q&A-Teacher, use the floor method for random questions and never take the maximum value. Why not use round? -PHP Chinese website Q&A

    Let’s take a look and learn.

    reply
    0
  • 阿神

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

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

    reply
    0
  • Cancelreply