33选6吧,后面的 13 是怎么回事?
下边是随机 33 个中选择6个的代码。
啊,忘了问你是用什么编程语言了,这个是拿Java写的
import java.util.ArrayList;
import java.util.List;
public class _33to6 {
public static void main(String[] args) {
List array = new ArrayList();
for (int i = 1; i <= 33; i++) {
array.add(i);
}
int[] result = new int[6];
for (int i = 0; i < result.length; i++) {
int random = (int) (Math.random() * 1000);
random = random % array.size();
result[i] = (Integer) array.get(random);
array.remove(random);
}
for (int i = 0; i < result.length; i++) {
System.out.print(result[i] + "\t");
}
}
}
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class Main {
private static DecimalFormat formater = new DecimalFormat("00");
public static void main(String[] args) {
// 第一个参数 "5" 为 随机选取的个数,即选取5注, 后面的参数为可能出的号码
String[] arg = { "5", "1", "3", "2", "6", "18", "14", "22", "33", "21", "15", "19", "8", "9", "11" };
start(arg);
// start(args);
}
public static void start(String[] args) {
int count = Integer.parseInt(args[0]);
List
for (int i = 1; i < args.length; i++)
queue.add(Integer.parseInt(args[i]));
Set
long number = combination(6, args.length - 1);
System.out.println("可能出现的号码个数为:" + (args.length - 1) + "个.");
System.out.println("该号码下随机组合数为:" + number + "个.");
System.out.println("本次提取随机组合数为:" + count + "个.");
System.out.println("随机结果为:");
for (Iterator
System.out.println(iterator.next());
}
public static Set
Set
while (result.size() < count) {
Collections.shuffle(queue);
String[] temp = { formater.format(queue.get(0)), formater.format(queue.get(1)), formater.format(queue.get(2)), formater.format(queue.get(3)), formater.format(queue.get(4)),
formater.format(queue.get(5)) };
Arrays.sort(temp);
result.add(temp[0] + " " + temp[1] + " " + temp[2] + " " + temp[3] + " " + temp[4] + " " + temp[5]);
}
return result;
}
public static long combination(int n, int m) {
long nf = 1L, mf = 1L;
for (int i = n; i >= 1; i--) {
nf *= i;
mf *= m + 1 - i;
}
return mf / nf;
}
}
确定13个球中有6个球是下期会出的号码,编程13选6排列输出结果???
请描述清楚问题!
public static void main(String[] args) {
List
Random r=new Random();
int i=1;
while(true){
list.add(i++);
if(i>33)
{break;}
}
for(int n=0;n<6;n++){
int random=r.nextInt(list.size());
int a=list.get(random);
System.out.println(a);
list.remove(random);
}
}