I have worked on a Linear Congruential Generator and the code is nearly perfect, except for one thing, I have two Modulus. If I replace or remove any one of them, I don't get any output, except for the counter which initiates at the end but it's pretty useless if there's no output to process using the counter. I need the application to output the numbers in a range from 0 to 9 and then output the distribution of the numbers at the end. Here is my code:
int fact;
int constant;
int modulus;
int seed;
Scanner scan = new Scanner(System.in);
System.out.println("Input fact: ");
fact = scan.nextInt();
System.out.println("Input constant: ");
constant = scan.nextInt();
System.out.println("Input modulus: ");
modulus = scan.nextInt();
System.out.println("Input seed: ");
seed = scan.nextInt();
int [] arrayBox;
arrayBox = new int [10];
for (int i = 0; i < 10; i++){
seed = (seed * fact + constant) % modulus; //First modulus
System.out.println(seed);
arrayBox[seed % 10] = arrayBox[seed % 10]+1; //Second modulus
}
for (int i = 0; i < 10; i++){
System.out.print( + (100*arrayBox[i]/10) + "% ");
}
Can anyone help me find a way around the second modulus and still get my output and counter working in the range that i want (0 to 9)?
Aucun commentaire:
Enregistrer un commentaire