Math.random() versus Random.nextInt(int)

后端 未结 4 1385
灰色年华
灰色年华 2020-11-22 07:21

What is the difference between Math.random() * n and Random.nextInt(n) where n is an integer?

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 08:03

    According to https://forums.oracle.com/forums/thread.jspa?messageID=6594485� Random.nextInt(n) is both more efficient and less biased than Math.random() * n

提交回复
热议问题