- λμλ₯Ό μμ±νλ ν΄λμ€μ΄λ€.
- integer, float, double, long, boolean νμ μ λμλ₯Ό μμ±ν μ μλ€.
- λ©μλμ μΈμλ₯Ό μ λ¬νμ¬ λμμ μνμ μ§μ ν μ μλ€.
package lesson06;
import java.util.Random;
public class Quiz03 {
public static void main(String[] args) {
Random rand = new Random();
// integer
System.out.println(rand.nextInt()); // μ μ μ 체 λ²μμ λμ
System.out.println(rand.nextInt(10)); // 0λΆν° 10 λ―Έλ§μ λμ
// double
System.out.println(rand.nextDouble()); // μ€μ μ 체 λ²μμ λμ
System.out.println(rand.nextDouble(0.5)); // 0.0λΆν° 0.5 λ―Έλ§μ λμ
// boolean
System.out.println(rand.nextBoolean()); // true λλ false
}
}
π https://docs.oracle.com/javase/8/docs/api/java/util/Random.html
π https://www.geeksforgeeks.org/generating-random-numbers-in-java