A pseudorandom number generator, such as java.util.Random
, produces a deterministic sequence of numbers characterized by the initial seed. Such generators are crafted to produce sequences that appear to vary randomly and (usually) uniformly over the whole range of the PRNG.
You get the same sequence of numbers if you start with the same seed. That can be useful under some circumstances, but usually it is undesirable. In particular, your numbers will not have any appearance of randomness at all if you seed the PRNG with the same seed before generating each number.
But more subtle problems arise even if you seed the PRNG with different seeds before generating each number, including if you instantiate a new Random
instead of reusing an existing one. In this case, you are not guaranteed to have the same range or distribution of results, and your results may exhibit correlations that they would not exhibit if you seeded only once.
So, when you say
I am wondering under what circumstances that you would want to have a different seed for you random number generator.
, about the only reason I can think of for wanting to change seed within one run of your program is that you have published enough draws from the PRNG that you are concerned about someone determining its implementation and internal state, and therefore being able to predict subsequent numbers. This would be a concern in practice only under rather special circumstances.
On the other hand, you generally do want to choose a different seed each time your program runs, else it will generate the same sequence of random numbers each time.
Generally, you should seed your PRNG once, and then use it as much as needed, without reseeding. It's not necessarily wrong to use multiple, independent PRNGs, but the reasons for doing so are mostly organizational (e.g. not having to worry about synchronization, not having to provide for injecting a Random
instance) rather than functional.