检查线性同余生成器(PRNG)Java中的重复值

检查线性同余生成器(PRNG)Java中的重复值,java,arrays,random,Java,Arrays,Random,所以我正在创建一个程序,应该使用线性同余生成器来创建一个数字序列。我想互相比较输出,检查重复,然后让程序停止。然而,对于我当前的代码,在第一个生成的数字“55672”之后,代码停止了。我在excel中有一个生成器,显示了所有的输出,并且没有重复。我做错了什么?这甚至是比较它们的一种可能的方法,因为我基本上会问x[I]=x[I],因为它会循环包括I变量在内的所有数字,从而返回true tl;dr我如何进行重复的it检查 public class Pseudotilfaeldigetal { pu

所以我正在创建一个程序,应该使用线性同余生成器来创建一个数字序列。我想互相比较输出,检查重复,然后让程序停止。然而,对于我当前的代码,在第一个生成的数字“55672”之后,代码停止了。我在excel中有一个生成器,显示了所有的输出,并且没有重复。我做错了什么?这甚至是比较它们的一种可能的方法,因为我基本上会问x[I]=x[I],因为它会循环包括I变量在内的所有数字,从而返回true

tl;dr我如何进行重复的it检查

public class Pseudotilfaeldigetal {

public static int[] x = new int[1000];
public static int modulus = 86408;
public static int a = 43205;
public static int c = 12345;
public static int seed;

public static Scanner tastatur = new Scanner(System.in); // her navngives vores scanner til tastatur

public static void main(String[] args) {

    algoritme(modulus, seed, a, c);
}

public static void algoritme(int modulus, int seed, int a, int c) {
    System.out.println("Select your seed ");
    x[0] = tastatur.nextInt(); //reads the next input, and uses as seed

    for (int i = 1; i < x.length; i++) { //Main for loop that generates numbers
        x[i] = (a * x[i - 1] + c) % modulus; //the number generation using LCG method
        System.out.println(x[i]); // Prints the newly generated value
        for (int j = 1; j < x.length; j++) { // cycles through all int in x[] array to check
            if (x[i] == x[j]) { //if current number is already in array
                System.out.println("Value has been repeated"); //Prints value already used
                return; // program ends. 
            }
        }
    }
}}
公共类伪TILFAELDIGETAL{
公共静态整数[]x=新整数[1000];
公共静态int模数=86408;
公共静态int a=43205;
公共静态int c=12345;
公共种子;
public static Scanner tastatur=新的扫描仪(System.in);//她的导航程序在tastatur之前一直使用扫描仪
公共静态void main(字符串[]args){
算法(模数、种子、a、c);
}
公共静态无效算法(整数模、整数种子、整数a、整数c){
System.out.println(“选择您的种子”);
x[0]=tastatur.nextInt();//读取下一个输入,并将其用作种子
for(int i=1;i
您不需要将i与i进行比较,只需要比较数组中以前所在位置的值

for (int j = 1; j < i; j++) { // cycles through values before x[i]
for(int j=1;j
为什么循环从1开始而不是从0开始?您的目标是什么?您是否试图确定发电机的循环长度?