- Math.random()メソッドを利用して、0~1までの乱数を生成する
double randomNum = Math.random();
- RandomクラスのnextInt()メソッドを使って、指定した範囲の乱数を生成する。
Random random = new Random();
int randomInt = random.nextInt(100);
- ThreadLocalRandomクラスのnextInt()メソッドを使用して、指定範囲内でランダムな整数値を生成します。
int randomInt = ThreadLocalRandom.current().nextInt(0, 100);
- SecureRandomクラスのnextInt()メソッドを使用して安全な乱数を生成する:
SecureRandom random = new SecureRandom();
int randomInt = random.nextInt(100);
- Apache Commons MathライブラリのRandomDataGeneratorクラスで指定された範囲内の乱数を生成する:
RandomDataGenerator randomDataGenerator = new RandomDataGenerator();
int randomInt = randomDataGenerator.nextInt(0, 100);