0

After making a seeded random number generator with Java, I get the same results on both Eclipse and Net Beans regardless of the time I run the code. I tried changing the seed, but I see no predictable pattern in how it influences the output, which would make sense if the results were random. However, it appears the results are not even pseudo-random because they are the same every time. Other than reproducible results, are there any practical applications of a seeded random number generator for a program such as this one? Furthermore, is there indeed a predictable pattern to how changing the seed will influence the output?

package evilSeed;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class EvilSeed {
    public static void main(String[] args) {
        Random rand = new Random(666);
        Map<Integer, Integer> m = new HashMap<Integer, Integer>();
        for (int i = 0; i < 10000; i++) {
            int r = rand.nextInt(20);
            Integer freq = m.get(r);
            m.put(r, freq == null ? 1 : freq + 1);
        }
        System.out.println(m);
    }
}

/*
{0=499, 1=496, 2=526, 3=507, 4=493, 5=491, 6=497, 7=466, 8=456, 9=513, 10=494, 
11=490, 12=515, 13=507, 14=547, 15=475, 16=524, 17=495, 18=504, 19=505}
*/
K Man
  • 602
  • 2
  • 9
  • 21

0 Answers0