Math.random() 返回带正号的 double 值,该值大于等于 0.0 且小于 1.0。Math.random() * 2 就是返回 [0,2) 转为整数就是0和1由于括号改变运算优先级 所以(int)Math.random() * 2 返回的永远是0 (int)(Math.random() * 2) 返回的是0和1
只是0.random作用是生成一个0~1.0的double数