Why 2^31 is not divisible by n?

前端 未结 3 1310
梦如初夏
梦如初夏 2021-01-18 15:39

http://docs.oracle.com/javase/6/docs/api/java/util/Random.html#nextInt%28int%29 says:

The algorithm is slightly tricky. It rejects values that would r

3条回答
  •  离开以前
    2021-01-18 15:51

    2^31 is only divisibale by a power or 2. When you check the code, this special case is treated separately without a loop. The Description is related to the rejecting-process, and there n is not a power of 2.

提交回复
热议问题