双色球模拟

package demo;


import java.util.Random;


public class RandomDemo {


public static void main(String[] args) {
// TODO Auto-generated method stub


Random r = new Random();
// Random对象,产生0-4内的随机数(产生0~n-1内的随机数)
int num = r.nextInt(5);


// 模拟篮球
// 产生1~n内的随机数
int blue = r.nextInt(16) + 1;
System.out.println("篮球:" + blue);


// // 模拟红球
// // 字符串缓冲类,字符串变量,线程非安全,但操作效率高,推荐使用
// StringBuilder red = new StringBuilder();
// // 产生6个红球
// for (int i = 0; i < 6; i++) {
// // arr.length=33
// // r.nextInt(arr.length)产生0~32内的随机数
// int x = r.nextInt(33) + 1;
// red.append(x + " ");
// }
// System.out.println("红球:" + red);


// 模拟红球2
// 种子
String[] arr = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
"31", "32", "33" };
// 字符串缓冲类,字符串变量,线程非安全,但操作效率高,推荐使用
StringBuilder red = new StringBuilder();
// 产生6个红球
for (int i = 0; i < 6; i++) {
red.append(arr[r.nextInt(arr.length)] + " ");
}
System.out.println("红球:" + red);


}
}

猜你喜欢

转载自blog.csdn.net/qq_30944053/article/details/79079866