+ 1
What is a seed parameter in method Random?
I encountered an instance of using a parameter called seed in defining a random object in java. It goes like this: Random rand= new Random(47); 47 is the seed. I was wondering what does the seed do?
3 odpowiedzi
+ 8
Random numbers are generated with an algorithm, and the seed determines what sequence it puts out. If you keep using the same seed, the algorithm will produce the same set of numbers every time you run the program.
Random() on its own (without a given seed) will generate one for itself using the comps. clock.
+ 10
Sometimes it may be useful for testing, to make sure calculations are working correctly (you'll know what's going in every time and expect a certain result) or if an issue is replicatable under the same circumstances.
Anyway, yw :D
+ 3
So why someone wants to use the same sequence of randoms over and over. Somehow it conflicts with the essence of randomness. Anyway thanks for your answer.