2014年11月30日日曜日

テスト対策、乱数

Random rand = new Random();

// 0~9
int r10 = rand.nextInt(10);

//10~99
int r10_99 = rand.nextInt(90) + 10;

//-50~50
int r_50_50 = rand.nextInt(101) - 50;

//0~10までの奇数
int odd = rand.nextInt(5) * 2 + 1;

//0~10までの偶数
int even = rand.nextInt(6) * 2;

//0.0以上10.0未満の浮動小数
double d = rand.nextDouble * 10;

0 件のコメント:

コメントを投稿