import java.util.Random; public class RandomTest { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ //Randomクラスの生成(シード指定なし) Random rnd = new Random(); //[1] //乱数を取得する int iValue = rnd.nextInt(); //[2] int iValue2 = rnd.nextInt(); //[3] int iValue3 = rnd.nextInt(100); //[4] int iValue4 = rnd.nextInt(100) + 100; //[5] long lValue = rnd.nextLong(); //[6] double dValue = rnd.nextDouble(); //[7] float fValue = rnd.nextFloat(); //[8] boolean bValue = rnd.nextBoolean(); //[9] //取得した値を出力 System.out.println("[2]int型: " + iValue); System.out.println("[3]int型(2回目): " + iValue2); System.out.println("[4]int型(0-99): " + iValue3); System.out.println("[5]int型(100-199): " + iValue4); System.out.println("[6]long型: " + lValue); System.out.println("[7]double型: " + dValue); System.out.println("[8]float型: " + fValue); System.out.println("[9]boolean型: " + bValue); long seed = 1000; //シードを指定 //Randomクラスの生成(シード指定あり) Random rndSeed = new Random(seed); //[10] int iValueSd = rndSeed.nextInt(); //[11] int iValueSd2 = rndSeed.nextInt(); //[12] //シードを指定して取得した値を出力 System.out.println("[11]シード指定int型: " + iValueSd); System.out.println("[12]シード指定]int型(2回目): " + iValueSd2); //同じシードで別のRandomクラスを生成 Random rndSeed2 = new Random(seed); //[13] int iValueSd3 = rndSeed2.nextInt(); //[14] int iValueSd4 = rndSeed2.nextInt(); //[15] //取得した値を出力 System.out.println("[14]同一シード指定int型: " + iValueSd3); System.out.println("[15]同一シード指定int型(2回目): " + iValueSd4); } }