Soheny.P 2021. 11. 1. 20:52
728x90
package kr.co.goodee39.date1101;

import java.util.Random;

public class Ex04Random {

	public static void main(String[] args) {
		double d = Math.random();
		System.out.println(d);
		
		
		// 0.99999 ~ 0.00001 * 6 = 5.99999 ~ 0.00006 (int) > 5 ~ 0 + 1 > 6 ~ 1
		int i = (int) (Math.random() * 6) + 1;
		System.out.println(i);
		
		Random ran = new Random();
		
		//0.00000 ~ 0.99999 사이 값 랜덤 출력
		System.out.println(ran.nextDouble());
		
		//정수형 int 최소 ~ int 최대사이 값 랜덤 출력
		System.out.println(ran.nextInt());
		
		//정수형 int 0 ~ 지정한 범위사이 값 랜덤 출력
		System.out.println(ran.nextInt(5));
		
		//논리형으로 T/F값을 랜덤하게 출력
		System.out.println(ran.nextBoolean());
	}

}

728x90