我正在尝试使用蒙特卡罗算法计算下周乐透号码包含连续数字的概率。我决定对号码进行排序,以便更容易地找到连续的数字,但在网上搜索了很长时间后,没有找到适合我需求的资料。
import java.util.Random;
import java.util.Arrays;
public class lotto {
public static String getLottoTicket(){
String lottoTicket = "";
Random lottoNumbers = new Random(); //random object
int [] ticket = new int[6]; //6 lotto numbers
int counterr = 0;
int a;
for( int counter = 0; counter < ticket.length; ++counter ){
ticket[counter] = (1 + lottoNumbers.nextInt(45) ); //numbers between 1-45
}
Arrays.sort( ticket ); //array class .. sorts array
for(int counter = 0; counter < ticket.length; ++counter ){
lottoTicket += ticket[counter];
lottoTicket += " ";
}
return lottoTicket;
}
public static void main( String [] args ){
int a, d, n=1, t, b;
for(int i=1; i<1000000; i++){
int counter = 0;
System.out.println( getLottoTicket() );
}
}
}
目前我所拥有的是使用计数器来查找百万结果中连续数字的数量,但我真的不知道如何实际找到连续数字。