使用 Android 时 Java 中的随机数
我需要创建一个介于 1 和 20 之间的随机数,并根据该数字(使用“If - Then”语句),我需要设置 ImageView 的图像。
我知道在Objective-C中,它是这样的:
int aNumber = arc4Random() % 20;
if (aNumber == 1) {
[theImageView setImage:theImage];
}
如何在Java中执行此操作?我已经看到它以这种方式完成,但我不明白如何设置数字范围(1-20,2-7等)。
int aNumber = (int) Math.random()