Java中可以使用java.util.Random
类来生成随机数。下面是一些常见的随机数运用的示例:
import java.util.Random;
Random random = new Random();
int randomNumber = random.nextInt();
System.out.println(randomNumber);
import java.util.Random;
Random random = new Random();
int min = 1;
int max = 10;
int randomNumber = random.nextInt(max - min + 1) + min;
System.out.println(randomNumber);
import java.util.Random;
Random random = new Random();
double randomNumber = random.nextDouble();
System.out.println(randomNumber);
import java.util.Random;
Random random = new Random();
boolean randomBoolean = random.nextBoolean();
System.out.println(randomBoolean);
这些只是一些常见的使用示例,还有很多其他用法和方法可以根据具体需求来使用。