# 자바 임의의 정수 생성법 알려주세요!
## 답변 자바에서 임의의 정수는, 크게 두 가지 방법으로 만듭니다. 1. Math.random() 2. Random.nextInt(int n) ## Math.random() 위 메소드는, 0.0 ~ 1.0 사이의 실수를 반환합니다. ( 0 <= randNum < 1) ## Random.nextInt(int n) 해당 메소드는, 0을 포함 n 미만의 임의의 정수를 반환합니다. ## 코드 예 주사위 값(1부터 6사이의 정수) 만들기 예 ``` // Math.random() int a = (int) (Math.random() * 6) + 1; // Random.nextInt(int n) Random rand = new Random(); int b = rand.nextInt(6) + 1; ``` ## 참고자료 --- 1. https://goo.gl/A2nWCC