I have made a very basic linear congruential generator (or at least I think I have) however it returns some crazy values including negative numbers. I cant for the life of me figure out why, any help very welcome. My code is below:
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long a = 252149039;
int c = 11;
long m =(long) Math.pow(2, 48);
long seed = System.currentTimeMillis();
System.out.println("How many Random numbers would you like to get?");
int number = scanner.nextInt();
for (int i = 0; i <= number;i++) {
seed = ((a*seed)+c) % m;
System.out.println(seed);
}
scanner.close();
}
Aucun commentaire:
Enregistrer un commentaire